| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chromecast/browser/test/chromecast_browser_test.h" | 5 #include "chromecast/browser/test/cast_browser_test.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "chromecast/base/chromecast_switches.h" |
| 10 #include "chromecast/base/metrics/cast_metrics_helper.h" | 11 #include "chromecast/base/metrics/cast_metrics_helper.h" |
| 11 #include "chromecast/browser/cast_browser_context.h" | 12 #include "chromecast/browser/cast_browser_context.h" |
| 12 #include "chromecast/browser/cast_browser_process.h" | 13 #include "chromecast/browser/cast_browser_process.h" |
| 13 #include "chromecast/browser/cast_content_window.h" | 14 #include "chromecast/browser/cast_content_window.h" |
| 14 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/browser/render_process_host.h" | 16 #include "content/public/browser/render_process_host.h" |
| 16 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 18 #include "content/public/common/content_switches.h" |
| 17 #include "content/public/test/browser_test_utils.h" | 19 #include "content/public/test/browser_test_utils.h" |
| 18 #include "content/public/test/test_navigation_observer.h" | 20 #include "content/public/test/test_navigation_observer.h" |
| 19 | 21 |
| 20 namespace chromecast { | 22 namespace chromecast { |
| 21 namespace shell { | 23 namespace shell { |
| 22 | 24 |
| 23 ChromecastBrowserTest::ChromecastBrowserTest() {} | 25 CastBrowserTest::CastBrowserTest() {} |
| 24 | 26 |
| 25 ChromecastBrowserTest::~ChromecastBrowserTest() {} | 27 CastBrowserTest::~CastBrowserTest() {} |
| 26 | 28 |
| 27 void ChromecastBrowserTest::SetUp() { | 29 void CastBrowserTest::SetUp() { |
| 28 SetUpCommandLine(base::CommandLine::ForCurrentProcess()); | 30 SetUpCommandLine(base::CommandLine::ForCurrentProcess()); |
| 29 | 31 |
| 30 BrowserTestBase::SetUp(); | 32 BrowserTestBase::SetUp(); |
| 31 } | 33 } |
| 32 | 34 |
| 33 void ChromecastBrowserTest::TearDownOnMainThread() { | 35 void CastBrowserTest::TearDownOnMainThread() { |
| 34 web_contents_.reset(); | 36 web_contents_.reset(); |
| 35 window_.reset(); | 37 window_.reset(); |
| 36 | 38 |
| 37 BrowserTestBase::TearDownOnMainThread(); | 39 BrowserTestBase::TearDownOnMainThread(); |
| 38 } | 40 } |
| 39 | 41 |
| 40 void ChromecastBrowserTest::RunTestOnMainThreadLoop() { | 42 void CastBrowserTest::SetUpCommandLine(base::CommandLine* command_line) { |
| 43 BrowserTestBase::SetUpCommandLine(command_line); |
| 44 |
| 45 command_line->AppendSwitch(switches::kNoWifi); |
| 46 command_line->AppendSwitchASCII(switches::kTestType, "browser"); |
| 47 } |
| 48 |
| 49 void CastBrowserTest::RunTestOnMainThreadLoop() { |
| 41 // Pump startup related events. | 50 // Pump startup related events. |
| 42 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 51 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 43 base::RunLoop().RunUntilIdle(); | 52 base::RunLoop().RunUntilIdle(); |
| 44 | 53 |
| 45 metrics::CastMetricsHelper::GetInstance()->SetDummySessionIdForTesting(); | 54 metrics::CastMetricsHelper::GetInstance()->SetDummySessionIdForTesting(); |
| 46 | 55 |
| 47 SetUpOnMainThread(); | 56 SetUpOnMainThread(); |
| 48 RunTestOnMainThread(); | 57 RunTestOnMainThread(); |
| 49 TearDownOnMainThread(); | 58 TearDownOnMainThread(); |
| 50 } | 59 } |
| 51 | 60 |
| 52 content::WebContents* ChromecastBrowserTest::NavigateToURL(const GURL& url) { | 61 content::WebContents* CastBrowserTest::NavigateToURL(const GURL& url) { |
| 53 window_ = base::MakeUnique<CastContentWindow>(); | 62 window_ = base::MakeUnique<CastContentWindow>(); |
| 54 | 63 |
| 55 web_contents_ = window_->CreateWebContents( | 64 web_contents_ = window_->CreateWebContents( |
| 56 CastBrowserProcess::GetInstance()->browser_context()); | 65 CastBrowserProcess::GetInstance()->browser_context()); |
| 57 window_->CreateWindowTree(web_contents_.get()); | 66 window_->CreateWindowTree(web_contents_.get()); |
| 58 content::WaitForLoadStop(web_contents_.get()); | 67 content::WaitForLoadStop(web_contents_.get()); |
| 59 | 68 |
| 60 content::TestNavigationObserver same_tab_observer(web_contents_.get(), 1); | 69 content::TestNavigationObserver same_tab_observer(web_contents_.get(), 1); |
| 61 content::NavigationController::LoadURLParams params(url); | 70 content::NavigationController::LoadURLParams params(url); |
| 62 params.transition_type = ui::PageTransitionFromInt( | 71 params.transition_type = ui::PageTransitionFromInt( |
| 63 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR); | 72 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR); |
| 64 web_contents_->GetController().LoadURLWithParams(params); | 73 web_contents_->GetController().LoadURLWithParams(params); |
| 65 same_tab_observer.Wait(); | 74 same_tab_observer.Wait(); |
| 66 | 75 |
| 67 return web_contents_.get(); | 76 return web_contents_.get(); |
| 68 } | 77 } |
| 69 | 78 |
| 70 } // namespace shell | 79 } // namespace shell |
| 71 } // namespace chromecast | 80 } // namespace chromecast |
| OLD | NEW |