1 // Copyright 2019 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "chrome/test/base/android/android_browser_test.h"
6 
7 #include "base/command_line.h"
8 #include "chrome/browser/ui/android/tab_model/tab_model.h"
9 #include "chrome/browser/ui/android/tab_model/tab_model_list.h"
10 #include "chrome/test/base/test_launcher_utils.h"
11 #include "content/public/test/test_utils.h"
12 
AndroidBrowserTest()13 AndroidBrowserTest::AndroidBrowserTest() {
14   CreateTestServer(base::FilePath(FILE_PATH_LITERAL("chrome/test/data")));
15 }
16 
17 AndroidBrowserTest::~AndroidBrowserTest() = default;
18 
SetUp()19 void AndroidBrowserTest::SetUp() {
20   base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
21   SetUpCommandLine(command_line);
22   SetUpDefaultCommandLine(command_line);
23   ASSERT_TRUE(test_launcher_utils::CreateUserDataDir(&temp_user_data_dir_));
24 
25   BrowserTestBase::SetUp();
26 }
27 
SetUpDefaultCommandLine(base::CommandLine * command_line)28 void AndroidBrowserTest::SetUpDefaultCommandLine(
29     base::CommandLine* command_line) {
30   test_launcher_utils::PrepareBrowserCommandLineForTests(command_line);
31   test_launcher_utils::PrepareBrowserCommandLineForBrowserTests(
32       command_line, /*open_about_blank_on_launch=*/true);
33 }
34 
PreRunTestOnMainThread()35 void AndroidBrowserTest::PreRunTestOnMainThread() {
36 }
37 
PostRunTestOnMainThread()38 void AndroidBrowserTest::PostRunTestOnMainThread() {
39   for (size_t i = 0; i < TabModelList::size(); ++i) {
40     while (TabModelList::get(i)->GetTabCount())
41       TabModelList::get(i)->CloseTabAt(0);
42   }
43 
44   // Run any shutdown events from closing tabs.
45   content::RunAllPendingInMessageLoop();
46 }
47