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