By Tom Hals, Jack Queen and Dietrich Knauth (Reuters) -A trial in California challenging the legality of President Donald Trump's use of U.S. troops in Los Angeles has highlighted vulnerabilities in American laws and traditions against deploying the military to carry out domestic police work. San Francisco-based U.S. District Judge Charles Breyer is expected in the coming weeks to issue a ruling in the non-jury trial after hearing three days of testimony that ended on Wednesday. Gavin Newsom, the Democratic governor of the most-populous U.S. state, sued Trump after the Republican president deployed National Guard troops and active-duty Marines to Los Angeles in June amid protests against intensified federal immigration raids. Newsom has called Trump's deployment of troops an unlawful use of the military and is asking the judge to bar them from carrying out law enforcement activities. An 1878 law called the Posse Comitatus Act generally forbids the military from taking part in civilian law enforcement in the United States. The Justice Department has argued that the U.S. Constitution empowers a president to deploy troops domestically to protect federal personnel and property, citing Supreme Court precedent. California has said the troops deployed by Trump have strayed into law enforcement functions such as providing a "show of force" at a park in Los Angeles to deter protests and taking part in a raid on a marijuana farm about 100 miles (160 km) from the city. Justice Department lawyers told the judge that Trump acted within his powers and that the troops are not carrying out law enforcement duties. But military figures testified that armed troops and combat vehicles accompanied immigration agents on raids even when internal assessments showed low risk to personnel, and twice detained people for a short time. California Attorney General Rob Bonta said in a filing to the judge that if Trump prevails in the case, it "would usher in a vast and unprecedented shift in the role of the military in our society." White House spokesperson Abigail Jackson called California's lawsuit a political stunt and said of the troops that "any insinuation that they are performing law enforcement functions is false." QUELL PROTESTS When Trump ordered 700 Marines and 4,000 National Guard troops to Los Angeles, he said they were needed to quell protests in the second-most-populous U.S. city. Justice Department lawyer Eric Hamilton told the judge that 300 National Guard troops remained deployed. "Why is the federalized National Guard, even though it's been drawn down, still in place?" Breyer then asked. U.S. Army Major General Scott Sherman, who had served as commander of the military task force sent into Los Angeles, testified that military officials in the field have wide latitude to decide when protection of federal property and personnel is needed even in situations deemed low risk. Sherman testified that he was instructed, though he did not say by whom, that actions such as establishing security perimeters, controlling traffic and crowds and even detaining people were permissible whenever federal personnel and property were threatened. The judge pressed Hamilton to define the limits on the role of the military. Police face threats every day, and the Trump administration's argument would let the military be called in almost without limit, Breyer said. Hamilton disagreed with the judge's assessment and said most of the deployed troops were withdrawn as threats diminished. On the same day the trial ended, Trump ordered 800 National Guard troops to patrol in Washington, D.C., in response to what he described as rampant crime, though statistics show that violent crime has been declining. A president has more authority to use federal troops in the U.S. capital than in a state. The Justice Department also has argued that California had no legal right to bring the case, an issue that Breyer must decide. The Posse Comitatus Act is a federal criminal statute, and the department has argued that California cannot enforce it with a civil lawsuit. Criminal prosecutions are the only way to enforce it, the department said, though Breyer questioned if that were possible given legal immunity for the president for official acts taken in office under a 2024 Supreme Court ruling. "It's the absence of any limits to a national police force - that's what I'm sitting here trying to figure out," Breyer said. (Reporting by Tom Hals in Wilmington, Delaware, and Jack Queen and Dietrich Knauth in New York; Editing by Will Dunham)