Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 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/browser/chromeos/login/oobe_base_test.h" | |
| 6 | |
| 7 #include "base/command_line.h" | |
| 8 #include "base/message_loop/message_loop.h" | |
| 9 #include "base/path_service.h" | |
| 10 #include "chrome/browser/chrome_notification_types.h" | |
| 11 #include "chrome/browser/chromeos/login/existing_user_controller.h" | |
| 12 #include "chrome/browser/chromeos/login/fake_user_manager.h" | |
| 13 #include "chrome/browser/chromeos/net/network_portal_detector_test_impl.h" | |
| 14 #include "chrome/browser/lifetime/application_lifetime.h" | |
| 15 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" | |
| 16 #include "chrome/common/chrome_paths.h" | |
| 17 #include "chrome/common/chrome_switches.h" | |
| 18 #include "chromeos/chromeos_switches.h" | |
| 19 #include "content/public/browser/notification_observer.h" | |
| 20 #include "content/public/browser/notification_registrar.h" | |
| 21 #include "content/public/browser/notification_service.h" | |
| 22 #include "content/public/test/browser_test_utils.h" | |
| 23 #include "google_apis/gaia/gaia_switches.h" | |
| 24 #include "net/dns/mock_host_resolver.h" | |
| 25 #include "net/test/embedded_test_server/http_request.h" | |
| 26 #include "net/test/embedded_test_server/http_response.h" | |
| 27 | |
| 28 namespace chromeos { | |
| 29 | |
| 30 namespace { | |
| 31 | |
| 32 // Timeout while waiting for network connectivity during tests. | |
| 33 const int kTestNetworkTimeoutSeconds = 1; | |
| 34 | |
| 35 // Email of owner account for test. | |
| 36 const char kTestAccountId[] = "username@gmail.com"; | |
| 37 | |
| 38 const char kTestAuthCode[] = "fake-auth-code"; | |
| 39 const char kTestGaiaUberToken[] = "fake-uber-token"; | |
| 40 const char kTestAuthLoginAccessToken[] = "fake-access-token"; | |
| 41 const char kTestRefreshToken[] = "fake-refresh-token"; | |
| 42 const char kTestSessionSIDCookie[] = "fake-session-SID-cookie"; | |
| 43 const char kTestSessionLSIDCookie[] = "fake-session-LSID-cookie"; | |
| 44 const char kTestUserinfoToken[] = "fake-userinfo-token"; | |
| 45 const char kTestLoginToken[] = "fake-login-token"; | |
| 46 const char kTestAccessToken[] = "fake-access-token"; | |
| 47 const char kTestSyncToken[] = "fake-sync-token"; | |
| 48 const char kTestAuthLoginToken[] = "fake-oauthlogin-token"; | |
| 49 const char kTestClientId[] = "fake-client-id"; | |
| 50 const char kTestAppScope[] = | |
| 51 "https://www.googleapis.com/auth/userinfo.profile"; | |
|
xiyuan
2013/12/16 21:04:55
Line 36 - 51 seems not used.
zel
2013/12/16 21:27:38
Done.
| |
| 52 | |
| 53 // Note the path name must be the same as in shill stub. | |
| 54 const char kStubEthernetServicePath[] = "eth1"; | |
| 55 | |
| 56 } // namespace | |
| 57 | |
| 58 OobeBaseTest::OobeBaseTest() : network_portal_detector_(NULL) { | |
| 59 set_exit_when_last_browser_closes(false); | |
| 60 } | |
| 61 | |
| 62 OobeBaseTest::~OobeBaseTest() { | |
| 63 } | |
| 64 | |
| 65 void OobeBaseTest::SetUp() { | |
| 66 base::FilePath test_data_dir; | |
| 67 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); | |
| 68 embedded_test_server()->ServeFilesFromDirectory(test_data_dir); | |
| 69 embedded_test_server()->RegisterRequestHandler( | |
| 70 base::Bind(&FakeGaia::HandleRequest, base::Unretained(&fake_gaia_))); | |
| 71 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | |
| 72 // Stop IO thread here because no threads are allowed while | |
| 73 // spawning sandbox host process. See crbug.com/322732. | |
| 74 embedded_test_server()->StopThread(); | |
| 75 | |
| 76 mock_user_manager_.reset(new MockUserManager); | |
| 77 AppLaunchController::SkipSplashWaitForTesting(); | |
| 78 AppLaunchController::SetNetworkWaitForTesting(kTestNetworkTimeoutSeconds); | |
|
xiyuan
2013/12/16 21:04:55
|mock_user_manager_| and the two AppLaunchControll
zel
2013/12/16 21:27:38
Done.
| |
| 79 | |
| 80 InProcessBrowserTest::SetUp(); | |
| 81 } | |
| 82 | |
| 83 void OobeBaseTest::SetUpInProcessBrowserTestFixture() { | |
| 84 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 85 network_portal_detector_ = new NetworkPortalDetectorTestImpl(); | |
| 86 NetworkPortalDetector::InitializeForTesting(network_portal_detector_); | |
| 87 network_portal_detector_->SetDefaultNetworkPathForTesting( | |
| 88 kStubEthernetServicePath); | |
| 89 } | |
| 90 | |
| 91 void OobeBaseTest::SetUpOnMainThread() { | |
| 92 // Restart the thread as the sandbox host process has already been spawned. | |
| 93 embedded_test_server()->RestartThreadAndListen(); | |
| 94 } | |
| 95 | |
| 96 void OobeBaseTest::CleanUpOnMainThread() { | |
| 97 // If the login display is still showing, exit gracefully. | |
| 98 if (LoginDisplayHostImpl::default_host()) { | |
| 99 base::MessageLoop::current()->PostTask(FROM_HERE, | |
| 100 base::Bind(&chrome::AttemptExit)); | |
| 101 content::RunMessageLoop(); | |
| 102 } | |
| 103 } | |
| 104 | |
| 105 void OobeBaseTest::SetUpCommandLine(CommandLine* command_line) { | |
| 106 command_line->AppendSwitch(chromeos::switches::kLoginManager); | |
| 107 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests); | |
| 108 command_line->AppendSwitch(::switches::kDisableBackgroundNetworking); | |
| 109 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user"); | |
| 110 | |
| 111 // Create gaia and webstore URL from test server url but using different | |
| 112 // host names. This is to avoid gaia response being tagged as from | |
| 113 // webstore in chrome_resource_dispatcher_host_delegate.cc. | |
| 114 const GURL& server_url = embedded_test_server()->base_url(); | |
| 115 | |
| 116 std::string gaia_host("gaia"); | |
| 117 GURL::Replacements replace_gaia_host; | |
| 118 replace_gaia_host.SetHostStr(gaia_host); | |
| 119 GURL gaia_url = server_url.ReplaceComponents(replace_gaia_host); | |
| 120 command_line->AppendSwitchASCII(::switches::kGaiaUrl, gaia_url.spec()); | |
| 121 command_line->AppendSwitchASCII(::switches::kLsoUrl, gaia_url.spec()); | |
| 122 command_line->AppendSwitchASCII(::switches::kGoogleApisUrl, | |
| 123 gaia_url.spec()); | |
| 124 fake_gaia_.Initialize(); | |
| 125 } | |
| 126 | |
| 127 void OobeBaseTest::SimulateNetworkOffline() { | |
| 128 NetworkPortalDetector::CaptivePortalState offline_state; | |
| 129 offline_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE; | |
| 130 network_portal_detector_->SetDetectionResultsForTesting( | |
| 131 kStubEthernetServicePath, offline_state); | |
| 132 network_portal_detector_->NotifyObserversForTesting(); | |
| 133 } | |
| 134 | |
| 135 base::Closure OobeBaseTest::SimulateNetworkOfflineClosure() { | |
| 136 return base::Bind(&OobeBaseTest::SimulateNetworkOffline, | |
| 137 base::Unretained(this)); | |
| 138 } | |
| 139 | |
| 140 void OobeBaseTest::SimulateNetworkOnline() { | |
| 141 NetworkPortalDetector::CaptivePortalState online_state; | |
| 142 online_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE; | |
| 143 online_state.response_code = 204; | |
| 144 network_portal_detector_->SetDetectionResultsForTesting( | |
| 145 kStubEthernetServicePath, online_state); | |
| 146 network_portal_detector_->NotifyObserversForTesting(); | |
| 147 } | |
| 148 | |
| 149 base::Closure OobeBaseTest::SimulateNetworkOnlineClosure() { | |
| 150 return base::Bind(&OobeBaseTest::SimulateNetworkOnline, | |
| 151 base::Unretained(this)); | |
| 152 } | |
| 153 | |
| 154 void OobeBaseTest::SimulateNetworkPortal() { | |
| 155 NetworkPortalDetector::CaptivePortalState portal_state; | |
| 156 portal_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL; | |
| 157 network_portal_detector_->SetDetectionResultsForTesting( | |
| 158 kStubEthernetServicePath, portal_state); | |
| 159 network_portal_detector_->NotifyObserversForTesting(); | |
| 160 } | |
| 161 | |
| 162 base::Closure OobeBaseTest::SimulateNetworkPortalClosure() { | |
| 163 return base::Bind(&OobeBaseTest::SimulateNetworkPortal, | |
| 164 base::Unretained(this)); | |
| 165 } | |
| 166 | |
| 167 void OobeBaseTest::JsExpect(const std::string& expression) { | |
| 168 bool result; | |
| 169 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | |
| 170 GetLoginUI()->GetWebContents(), | |
| 171 "window.domAutomationController.send(!!(" + expression + "));", | |
| 172 &result)); | |
| 173 ASSERT_TRUE(result) << expression; | |
| 174 } | |
| 175 | |
| 176 content::WebUI* OobeBaseTest::GetLoginUI() { | |
| 177 return static_cast<chromeos::LoginDisplayHostImpl*>( | |
| 178 chromeos::LoginDisplayHostImpl::default_host())->GetOobeUI()->web_ui(); | |
| 179 } | |
| 180 | |
| 181 SigninScreenHandler* OobeBaseTest::GetSigninScreenHandler() { | |
| 182 return static_cast<chromeos::LoginDisplayHostImpl*>( | |
| 183 chromeos::LoginDisplayHostImpl::default_host()) | |
| 184 ->GetOobeUI() | |
| 185 ->signin_screen_handler_for_test(); | |
| 186 } | |
| 187 | |
| 188 WebUILoginDisplay* OobeBaseTest::GetLoginDisplay() { | |
| 189 ExistingUserController* controller = | |
| 190 ExistingUserController::current_controller(); | |
| 191 CHECK(controller); | |
| 192 return static_cast<WebUILoginDisplay*>( | |
| 193 controller->login_display()); | |
| 194 } | |
| 195 | |
| 196 } // namespace chromeos | |
| OLD | NEW |