File: media_router_integration_browsertest.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (568 lines) | stat: -rw-r--r-- 21,077 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/test/media_router/media_router_integration_browsertest.h"

#include <memory>

#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/json/json_file_value_serializer.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/path_service.h"
#include "base/strings/stringprintf.h"
#include "base/task/single_thread_task_runner.h"
#include "base/threading/thread_restrictions.h"
#include "base/types/cxx23_to_underlying.h"
#include "build/build_config.h"
#include "chrome/browser/media/router/media_router_feature.h"
#include "chrome/browser/media/router/mojo/media_router_desktop.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/media_router/media_cast_mode.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/ui_test_utils.h"
#include "chrome/test/media_router/media_router_cast_ui_for_test.h"
#include "chrome/test/media_router/media_router_gmc_ui_for_test.h"
#include "components/media_router/browser/media_router_factory.h"
#include "components/media_router/common/issue.h"
#include "components/policy/core/browser/browser_policy_connector.h"
#include "components/policy/policy_constants.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "media/base/media_switches.h"
#include "media/base/test_data_util.h"
#include "net/base/filename_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest-param-test.h"
#include "testing/gtest/include/gtest/gtest.h"

#if BUILDFLAG(IS_CHROMEOS)
#include "ash/constants/ash_features.h"
#endif  // BUILDFLAG(IS_CHROMEOS)

using content::WebContents;
using testing::Optional;

namespace media_router {

namespace {

std::string GetStartedConnectionId(WebContents* web_contents) {
  return EvalJs(web_contents, "startedConnection.id").ExtractString();
}

std::string GetDefaultRequestSessionId(WebContents* web_contents) {
  return EvalJs(web_contents, "defaultRequestSessionId").ExtractString();
}

// Routes observer that calls a callback once there are no routes.
class NoRoutesObserver : public MediaRoutesObserver {
 public:
  NoRoutesObserver(MediaRouter* router, base::OnceClosure callback)
      : MediaRoutesObserver(router), callback_(std::move(callback)) {}

  ~NoRoutesObserver() override = default;

  void OnRoutesUpdated(const std::vector<MediaRoute>& routes) override {
    if (callback_ && routes.empty())
      std::move(callback_).Run();
  }

 private:
  base::OnceClosure callback_;
};

}  // namespace

MediaRouterIntegrationBrowserTest::MediaRouterIntegrationBrowserTest(
    UiForBrowserTest test_ui_type)
    : test_ui_type_(test_ui_type) {
  feature_list_.InitWithFeatures(
      {
          media::kGlobalMediaControls,
#if BUILDFLAG(IS_CHROMEOS)
          // Without this flag, SodaInstaller::GetInstance() fails a DCHECK
          // on Chrome OS. The call to SodaInstaller::GetInstance() is in
          // MediaDialogView::AddedToWidget(), which is called indirectly
          // from MediaDialogView::ShowDialogForPresentationRequest().
          ash::features::kOnDeviceSpeechRecognition,
#else
          media::kGlobalMediaControlsUpdatedUI,
#endif
      },
      {});
}

MediaRouterIntegrationBrowserTest::~MediaRouterIntegrationBrowserTest() =
    default;

Browser* MediaRouterIntegrationBrowserTest::browser() {
  return InProcessBrowserTest::browser();
}

void MediaRouterIntegrationBrowserTest::SetUpCommandLine(
    base::CommandLine* command_line) {
  command_line->AppendSwitchASCII(
      switches::kAutoplayPolicy,
      // Needed to allow a video to autoplay from a browser test.
      switches::autoplay::kNoUserGestureRequiredPolicy);
  if (!RequiresMediaRouteProviders()) {
    // Disable built-in media route providers.
    command_line->AppendSwitch(kDisableMediaRouteProvidersForTestSwitch);
  }
}

void MediaRouterIntegrationBrowserTest::SetUp() {
  ParseCommandLine();
  InProcessBrowserTest::SetUp();
}

void MediaRouterIntegrationBrowserTest::InitTestUi() {
  auto* const web_contents = GetActiveWebContents();
  if (test_ui_) {
    test_ui_->TearDown();
  }
  switch (test_ui_type_) {
    case UiForBrowserTest::kCast:
      test_ui_ = std::make_unique<MediaRouterCastUiForTest>(web_contents);
      break;
    case UiForBrowserTest::kGmc:
      test_ui_ = std::make_unique<MediaRouterGmcUiForTest>(web_contents);
      break;
    default:
      NOTREACHED() << base::to_underlying(test_ui_type_);
  }
}

void MediaRouterIntegrationBrowserTest::TearDownOnMainThread() {
  test_ui_->TearDown();
  test_ui_.reset();
  test_provider_->TearDown();
  InProcessBrowserTest::TearDownOnMainThread();
  test_navigation_observer_.reset();
}

void MediaRouterIntegrationBrowserTest::SetUpInProcessBrowserTestFixture() {
  InProcessBrowserTest::SetUpInProcessBrowserTestFixture();
  EXPECT_CALL(provider_, IsInitializationComplete(testing::_))
      .WillRepeatedly(testing::Return(true));
  EXPECT_CALL(provider_, IsFirstPolicyLoadComplete(testing::_))
      .WillRepeatedly(testing::Return(true));
  policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_);
}

void MediaRouterIntegrationBrowserTest::SetUpOnMainThread() {
  MediaRouterDesktop* router = static_cast<MediaRouterDesktop*>(
      MediaRouterFactory::GetApiForBrowserContext(browser()->profile()));
  mojo::PendingRemote<mojom::MediaRouter> media_router_remote;
  mojo::PendingRemote<mojom::MediaRouteProvider> provider_remote;
  router->BindToMojoReceiver(
      media_router_remote.InitWithNewPipeAndPassReceiver());
  test_provider_ = std::make_unique<TestMediaRouteProvider>(
      provider_remote.InitWithNewPipeAndPassReceiver(),
      std::move(media_router_remote));
  router->RegisterMediaRouteProvider(mojom::MediaRouteProviderId::TEST,
                                     std::move(provider_remote));

  InitTestUi();
}

bool MediaRouterIntegrationBrowserTest::ConditionalWait(
    base::TimeDelta timeout,
    base::TimeDelta interval,
    const base::RepeatingCallback<bool(void)>& callback) {
  base::ElapsedTimer timer;
  do {
    if (callback.Run())
      return true;

    base::RunLoop run_loop;
    base::SingleThreadTaskRunner::GetCurrentDefault()->PostDelayedTask(
        FROM_HERE, run_loop.QuitClosure(), interval);
    run_loop.Run();
  } while (timer.Elapsed() < timeout);

  return false;
}

void MediaRouterIntegrationBrowserTest::Wait(base::TimeDelta timeout) {
  base::RunLoop run_loop;
  base::SingleThreadTaskRunner::GetCurrentDefault()->PostDelayedTask(
      FROM_HERE, run_loop.QuitClosure(), timeout);
  run_loop.Run();
}

void MediaRouterIntegrationBrowserTest::WaitUntilNoRoutes(
    WebContents* web_contents) {
  if (!test_provider_->HasRoutes())
    return;

  // TODO(crbug.com/1374499): There can't be a good reason to use the observer
  // API to check for routes asynchronously, which is fragile.  However, some
  // browser tests rely on this behavior.  Either add a callback parameter to
  // TerminateRoute, or add pass callback to the TestProvider to run when all
  // routes are gone.
  base::RunLoop run_loop;
  auto no_routes_observer = std::make_unique<NoRoutesObserver>(
      MediaRouterFactory::GetApiForBrowserContext(
          web_contents->GetBrowserContext()),
      run_loop.QuitClosure());
  run_loop.Run();
}

void MediaRouterIntegrationBrowserTest::ExecuteJavaScriptAPI(
    WebContents* web_contents,
    const std::string& script) {
  std::string result(EvalJs(web_contents, script).ExtractString());

  // Read the test result, the test result set by javascript is a
  // JSON string with the following format:
  // {"passed": "<true/false>", "errorMessage": "<error_message>"}
  std::optional<base::Value> value =
      base::JSONReader::Read(result, base::JSON_ALLOW_TRAILING_COMMAS);

  // Convert to dictionary.
  base::Value::Dict* dict_value = value->GetIfDict();
  ASSERT_TRUE(dict_value);

  // Extract the fields.
  const std::string* error_message = dict_value->FindString("errorMessage");
  ASSERT_TRUE(error_message);
  ASSERT_THAT(dict_value->FindBool("passed"), Optional(true))
      << error_message->c_str();
}

void MediaRouterIntegrationBrowserTest::StartSessionAndAssertNotFoundError() {
  OpenTestPage(FILE_PATH_LITERAL("basic_test.html"));
  WebContents* web_contents = GetActiveWebContents();
  CHECK(web_contents);
  ExecuteJavaScriptAPI(web_contents, "startSession();");

  // Wait to simulate the user waiting for any sinks to be displayed.
  Wait(base::Seconds(1));
  test_ui_->HideDialog();
  CheckStartFailed(web_contents, "NotFoundError", "No screens found.");
}

WebContents*
MediaRouterIntegrationBrowserTest::StartSessionWithTestPageAndSink() {
  OpenTestPage(FILE_PATH_LITERAL("basic_test.html"));
  WebContents* web_contents = GetActiveWebContents();
  CHECK(web_contents);
  ExecuteJavaScriptAPI(web_contents, "waitUntilDeviceAvailable();");
  ExecuteJavaScriptAPI(web_contents, "startSession();");
  test_ui_->WaitForDialogShown();
  return web_contents;
}

WebContents*
MediaRouterIntegrationBrowserTest::StartSessionWithTestPageAndChooseSink() {
  WebContents* web_contents = StartSessionWithTestPageAndSink();
  test_ui_->WaitForSinkAvailable(receiver_);
  test_ui_->StartCasting(receiver_);
  // TODO(takumif): Remove the HideDialog() call once the dialog can close
  // itself automatically after casting.
  test_ui_->HideDialog();
  return web_contents;
}

void MediaRouterIntegrationBrowserTest::OpenTestPage(
    base::FilePath::StringViewType file_name) {
  base::FilePath full_path = GetResourceFile(file_name);
  ASSERT_TRUE(
      ui_test_utils::NavigateToURL(browser(), GetTestPageUrl(full_path)));
}

void MediaRouterIntegrationBrowserTest::OpenTestPageInNewTab(
    base::FilePath::StringViewType file_name) {
  base::FilePath full_path = GetResourceFile(file_name);
  ui_test_utils::NavigateToURLWithDisposition(
      browser(), GetTestPageUrl(full_path),
      WindowOpenDisposition::NEW_FOREGROUND_TAB,
      ui_test_utils::BROWSER_TEST_WAIT_FOR_LOAD_STOP);
  // Opening a new tab creates new WebContents, so we must re-configure the
  // test UI for it.
  InitTestUi();
}

GURL MediaRouterIntegrationBrowserTest::GetTestPageUrl(
    const base::FilePath& full_path) {
  return net::FilePathToFileURL(full_path);
}

void MediaRouterIntegrationBrowserTest::CheckStartFailed(
    WebContents* web_contents,
    const std::string& error_name,
    const std::string& error_message_substring) {
  std::string script(base::StringPrintf("checkStartFailed('%s', '%s');",
                                        error_name.c_str(),
                                        error_message_substring.c_str()));
  ExecuteJavaScriptAPI(web_contents, script);
}

base::FilePath MediaRouterIntegrationBrowserTest::GetResourceFile(
    base::FilePath::StringViewType relative_path) const {
  const base::FilePath full_path =
      base::PathService::CheckedGet(base::DIR_OUT_TEST_DATA_ROOT)
          .Append(FILE_PATH_LITERAL("media_router/browser_test_resources/"))
          .Append(relative_path);
  {
    // crbug.com/724573
    base::ScopedAllowBlockingForTesting allow_blocking;
    CHECK(PathExists(full_path));
  }
  return full_path;
}

void MediaRouterIntegrationBrowserTest::ExecuteScript(
    const content::ToRenderFrameHost& adapter,
    const std::string& script) {
  ASSERT_TRUE(content::ExecJs(adapter, script));
}

bool MediaRouterIntegrationBrowserTest::IsRouteCreatedOnUI() {
  return !test_ui_->GetRouteIdForSink(receiver_).empty();
}

void MediaRouterIntegrationBrowserTest::ParseCommandLine() {
  base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();

  receiver_ = command_line->GetSwitchValueASCII("receiver");
  if (receiver_.empty())
    receiver_ = "test-sink-1";
}

void MediaRouterIntegrationBrowserTest::CheckSessionValidity(
    WebContents* web_contents) {
  ExecuteJavaScriptAPI(web_contents, "checkSession();");
  std::string session_id(GetStartedConnectionId(web_contents));
  EXPECT_FALSE(session_id.empty());
  std::string default_request_session_id(
      GetDefaultRequestSessionId(web_contents));
  EXPECT_EQ(session_id, default_request_session_id);
}

WebContents* MediaRouterIntegrationBrowserTest::GetActiveWebContents() {
  return browser()->tab_strip_model()->GetActiveWebContents();
}

void MediaRouterIntegrationBrowserTest::RunBasicTest() {
  WebContents* web_contents = StartSessionWithTestPageAndChooseSink();
  CheckSessionValidity(web_contents);
  ExecuteJavaScriptAPI(web_contents,
                       "terminateSessionAndWaitForStateChange();");
  WaitUntilNoRoutes(web_contents);
}

void MediaRouterIntegrationBrowserTest::RunSendMessageTest(
    const std::string& message) {
  WebContents* web_contents = StartSessionWithTestPageAndChooseSink();
  CheckSessionValidity(web_contents);
  ExecuteJavaScriptAPI(web_contents,
                       base::StringPrintf("sendMessageAndExpectResponse('%s');",
                                          message.c_str()));
}

void MediaRouterIntegrationBrowserTest::RunFailToSendMessageTest() {
  WebContents* web_contents = StartSessionWithTestPageAndChooseSink();
  CheckSessionValidity(web_contents);
  ExecuteJavaScriptAPI(web_contents, "closeConnectionAndWaitForStateChange();");
  ExecuteJavaScriptAPI(web_contents, "checkSendMessageFailed('closed');");
}

void MediaRouterIntegrationBrowserTest::RunReconnectSessionTest() {
  WebContents* web_contents = StartSessionWithTestPageAndChooseSink();
  CheckSessionValidity(web_contents);
  std::string session_id(GetStartedConnectionId(web_contents));
  OpenTestPageInNewTab(FILE_PATH_LITERAL("basic_test.html"));
  WebContents* new_web_contents = GetActiveWebContents();
  ASSERT_TRUE(new_web_contents);
  ASSERT_NE(web_contents, new_web_contents);
  ExecuteJavaScriptAPI(
      new_web_contents,
      base::StringPrintf("reconnectSession('%s');", session_id.c_str()));
  ASSERT_EQ(session_id,
            content::EvalJs(new_web_contents, "reconnectedSession.id"));

  ExecuteJavaScriptAPI(web_contents,
                       "terminateSessionAndWaitForStateChange();");
  WaitUntilNoRoutes(web_contents);
}

void MediaRouterIntegrationBrowserTest::RunFailedReconnectSessionTest() {
  WebContents* web_contents = StartSessionWithTestPageAndChooseSink();
  CheckSessionValidity(web_contents);
  std::string session_id(GetStartedConnectionId(web_contents));

  OpenTestPageInNewTab(FILE_PATH_LITERAL("fail_reconnect_session.html"));
  WebContents* new_web_contents = GetActiveWebContents();
  ASSERT_TRUE(new_web_contents);
  ASSERT_NE(web_contents, new_web_contents);
  test_provider_->set_route_error_message("Unknown route");
  ExecuteJavaScriptAPI(new_web_contents,
                       base::StringPrintf("checkReconnectSessionFails('%s')",
                                          session_id.c_str()));
  ExecuteJavaScriptAPI(web_contents,
                       "terminateSessionAndWaitForStateChange();");
  WaitUntilNoRoutes(web_contents);
}

void MediaRouterIntegrationBrowserTest::SetEnableMediaRouter(bool enable) {
  policy::PolicyMap policy;
  policy.Set(policy::key::kEnableMediaRouter, policy::POLICY_LEVEL_MANDATORY,
             policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD,
             base::Value(enable), nullptr);
  provider_.UpdateChromePolicy(policy);
  base::RunLoop().RunUntilIdle();
}

void MediaRouterIntegrationBrowserTest::RunReconnectSessionSameTabTest() {
  WebContents* web_contents = StartSessionWithTestPageAndChooseSink();
  CheckSessionValidity(web_contents);
  std::string session_id(GetStartedConnectionId(web_contents));
  ExecuteJavaScriptAPI(web_contents, "closeConnectionAndWaitForStateChange();");

  ExecuteJavaScriptAPI(
      web_contents,
      base::StringPrintf("reconnectSession('%s');", session_id.c_str()));
  ASSERT_EQ(session_id, content::EvalJs(web_contents, "reconnectedSession.id"));
}

bool MediaRouterIntegrationBrowserTest::RequiresMediaRouteProviders() const {
  return false;
}

// TODO(crbug.com/1238758): Test is flaky on Windows and Linux.
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_WIN)
#define MAYBE_Basic MANUAL_Basic
#elif BUILDFLAG(IS_CHROMEOS)
// TODO(crbug.com/380369297): Test fixture is not compatible with ChromeOS.
#define MAYBE_Basic DISABLED_Basic
#else
#define MAYBE_Basic Basic
#endif
IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, MAYBE_Basic) {
  RunBasicTest();
}

// TODO(crbug.com/40784325): Test is flaky on Windows and Linux.
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_WIN)
#define MAYBE_SendAndOnMessage MANUAL_SendAndOnMessage
#elif BUILDFLAG(IS_CHROMEOS)
// TODO(crbug.com/380369297): Test fixture is not compatible with ChromeOS.
#define MAYBE_SendAndOnMessage DISABLED_SendAndOnMessage
#else
#define MAYBE_SendAndOnMessage SendAndOnMessage
#endif
IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
                       MAYBE_SendAndOnMessage) {
  RunSendMessageTest("foo");
}

#if BUILDFLAG(IS_CHROMEOS)
// TODO(crbug.com/380369297): Test fixture is not compatible with ChromeOS.
#define MAYBE_CloseOnError DISABLED_CloseOnError
#else
#define MAYBE_CloseOnError CloseOnError
#endif
IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest, MAYBE_CloseOnError) {
  test_provider_->set_close_route_error_on_send();
  WebContents* web_contents = StartSessionWithTestPageAndChooseSink();
  CheckSessionValidity(web_contents);
  ExecuteJavaScriptAPI(web_contents,
                       "sendMessageAndExpectConnectionCloseOnError()");
}

// TODO(crbug.com/40784296): Test is flaky.
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_CHROMEOS)
#define MAYBE_Fail_SendMessage MANUAL_Fail_SendMessage
#else
#define MAYBE_Fail_SendMessage Fail_SendMessage
#endif
IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
                       MAYBE_Fail_SendMessage) {
  RunFailToSendMessageTest();
}

#if BUILDFLAG(IS_CHROMEOS)
// TODO(crbug.com/380369297): Test fixture is not compatible with ChromeOS.
#define MAYBE_Fail_CreateRoute DISABLED_Fail_CreateRoute
#else
#define MAYBE_Fail_CreateRoute Fail_CreateRoute
#endif
IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
                       MAYBE_Fail_CreateRoute) {
  test_provider_->set_route_error_message("Unknown sink");
  WebContents* web_contents = StartSessionWithTestPageAndChooseSink();
  CheckStartFailed(web_contents, "UnknownError", "Unknown sink");
}

#if BUILDFLAG(IS_CHROMEOS)
// TODO(crbug.com/380369297): Test fixture is not compatible with ChromeOS.
#define MAYBE_ReconnectSession DISABLED_ReconnectSession
#else
#define MAYBE_ReconnectSession ReconnectSession
#endif
IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
                       MAYBE_ReconnectSession) {
  RunReconnectSessionTest();
}

#if BUILDFLAG(IS_CHROMEOS)
// TODO(crbug.com/380369297): Test fixture is not compatible with ChromeOS.
#define MAYBE_Fail_ReconnectSession DISABLED_Fail_ReconnectSession
#else
#define MAYBE_Fail_ReconnectSession Fail_ReconnectSession
#endif
IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
                       MAYBE_Fail_ReconnectSession) {
  RunFailedReconnectSessionTest();
}

#if BUILDFLAG(IS_CHROMEOS)
// TODO(crbug.com/380369297): Test fixture is not compatible with ChromeOS.
#define MAYBE_Fail_StartCancelled DISABLED_Fail_StartCancelled
#else
#define MAYBE_Fail_StartCancelled Fail_StartCancelled
#endif
IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
                       MAYBE_Fail_StartCancelled) {
  WebContents* web_contents = StartSessionWithTestPageAndSink();
  test_ui_->HideDialog();
  CheckStartFailed(web_contents, "NotAllowedError", "Dialog closed.");
}

#if BUILDFLAG(IS_CHROMEOS)
// TODO(crbug.com/380369297): Test fixture is not compatible with ChromeOS.
#define MAYBE_Fail_StartCancelledNoSinks DISABLED_Fail_StartCancelledNoSinks
#else
#define MAYBE_Fail_StartCancelledNoSinks Fail_StartCancelledNoSinks
#endif
IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
                       MAYBE_Fail_StartCancelledNoSinks) {
  test_provider_->set_empty_sink_list();
  StartSessionAndAssertNotFoundError();
}

#if BUILDFLAG(IS_CHROMEOS)
// TODO(crbug.com/380369297): Test fixture is not compatible with ChromeOS.
#define MAYBE_Fail_StartCancelledNoSupportedSinks \
  DISABLED_Fail_StartCancelledNoSupportedSinks
#else
#define MAYBE_Fail_StartCancelledNoSupportedSinks \
  Fail_StartCancelledNoSupportedSinks
#endif
IN_PROC_BROWSER_TEST_F(MediaRouterIntegrationBrowserTest,
                       MAYBE_Fail_StartCancelledNoSupportedSinks) {
  test_provider_->set_unsupported_media_sources_list();
  StartSessionAndAssertNotFoundError();
}

}  // namespace media_router