SAN FRANCISCO—The first court trial to test whether “gig economy” workers should be treated as independent contractors or employees got underway Tuesday in what could be seen as the culmination of a series of legal battles that have dogged Silicon Valley.