OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/command_line.h" | |
5 #include "chrome/browser/signin/signin_promo.h" | 6 #include "chrome/browser/signin/signin_promo.h" |
6 #include "chrome/browser/ui/browser.h" | 7 #include "chrome/browser/ui/browser.h" |
7 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 8 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
9 #include "chrome/browser/ui/webui/signin/inline_login_ui.h" | |
10 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | |
11 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | |
8 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
9 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
10 #include "chrome/test/base/in_process_browser_test.h" | 14 #include "chrome/test/base/in_process_browser_test.h" |
15 #include "chrome/test/base/test_browser_window.h" | |
11 #include "chrome/test/base/test_chrome_web_ui_controller_factory.h" | 16 #include "chrome/test/base/test_chrome_web_ui_controller_factory.h" |
12 #include "chrome/test/base/testing_browser_process.h" | 17 #include "chrome/test/base/testing_browser_process.h" |
13 #include "chrome/test/base/ui_test_utils.h" | 18 #include "chrome/test/base/ui_test_utils.h" |
19 #include "content/public/browser/render_frame_host.h" | |
14 #include "content/public/browser/render_process_host.h" | 20 #include "content/public/browser/render_process_host.h" |
15 #include "content/public/browser/session_storage_namespace.h" | 21 #include "content/public/browser/session_storage_namespace.h" |
16 #include "content/public/browser/storage_partition.h" | 22 #include "content/public/browser/storage_partition.h" |
17 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
18 #include "content/public/browser/web_ui_controller.h" | 24 #include "content/public/browser/web_ui_controller.h" |
19 #include "content/public/common/url_constants.h" | 25 #include "content/public/common/url_constants.h" |
20 #include "content/public/test/browser_test_utils.h" | 26 #include "content/public/test/browser_test_utils.h" |
21 #include "content/public/test/test_navigation_observer.h" | 27 #include "content/public/test/test_navigation_observer.h" |
28 #include "google_apis/gaia/fake_gaia.h" | |
29 #include "google_apis/gaia/gaia_switches.h" | |
22 #include "net/base/url_util.h" | 30 #include "net/base/url_util.h" |
23 #include "net/test/embedded_test_server/embedded_test_server.h" | 31 #include "net/test/embedded_test_server/embedded_test_server.h" |
32 #include "net/test/embedded_test_server/http_request.h" | |
33 #include "net/test/embedded_test_server/http_response.h" | |
24 #include "testing/gmock/include/gmock/gmock.h" | 34 #include "testing/gmock/include/gmock/gmock.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
26 | 36 |
27 using ::testing::_; | 37 using ::testing::_; |
38 using ::testing::Invoke; | |
39 using ::testing::InvokeWithoutArgs; | |
28 | 40 |
29 namespace { | 41 namespace { |
30 | 42 |
31 struct ContentInfo { | 43 struct ContentInfo { |
32 ContentInfo(int pid, content::StoragePartition* storage_partition) { | 44 ContentInfo(int pid, content::StoragePartition* storage_partition) { |
33 this->pid = pid; | 45 this->pid = pid; |
34 this->storage_partition = storage_partition; | 46 this->storage_partition = storage_partition; |
35 } | 47 } |
36 | 48 |
37 int pid; | 49 int pid; |
(...skipping 20 matching lines...) Expand all Loading... | |
58 | 70 |
59 // Mock the TestChromeWebUIControllerFactory::WebUIProvider to prove that we are | 71 // Mock the TestChromeWebUIControllerFactory::WebUIProvider to prove that we are |
60 // not called as expected. | 72 // not called as expected. |
61 class FooWebUIProvider | 73 class FooWebUIProvider |
62 : public TestChromeWebUIControllerFactory::WebUIProvider { | 74 : public TestChromeWebUIControllerFactory::WebUIProvider { |
63 public: | 75 public: |
64 MOCK_METHOD2(NewWebUI, content::WebUIController*(content::WebUI* web_ui, | 76 MOCK_METHOD2(NewWebUI, content::WebUIController*(content::WebUI* web_ui, |
65 const GURL& url)); | 77 const GURL& url)); |
66 }; | 78 }; |
67 | 79 |
80 class MockLoginUIObserver : public LoginUIService::Observer { | |
81 public: | |
82 MOCK_METHOD0(OnUntrustedLoginUIShown, void()); | |
83 }; | |
84 | |
68 const char kFooWebUIURL[] = "chrome://foo/"; | 85 const char kFooWebUIURL[] = "chrome://foo/"; |
69 | 86 |
70 } // namespace | 87 } // namespace |
71 | 88 |
72 class InlineLoginUIBrowserTest : public InProcessBrowserTest { | 89 class InlineLoginUIBrowserTest : public InProcessBrowserTest { |
73 public: | 90 public: |
74 InlineLoginUIBrowserTest() {} | 91 InlineLoginUIBrowserTest() {} |
75 }; | 92 }; |
76 | 93 |
77 IN_PROC_BROWSER_TEST_F(InlineLoginUIBrowserTest, DifferentStorageId) { | 94 IN_PROC_BROWSER_TEST_F(InlineLoginUIBrowserTest, DifferentStorageId) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 " handler();" | 157 " handler();" |
141 "else" | 158 "else" |
142 " inline.login.getAuthExtHost().addEventListener('ready', handler);")); | 159 " inline.login.getAuthExtHost().addEventListener('ready', handler);")); |
143 | 160 |
144 std::string message; | 161 std::string message; |
145 do { | 162 do { |
146 ASSERT_TRUE(message_queue.WaitForMessage(&message)); | 163 ASSERT_TRUE(message_queue.WaitForMessage(&message)); |
147 } while (message != "\"ready\""); | 164 } while (message != "\"ready\""); |
148 } | 165 } |
149 | 166 |
167 // Executes JavaScript code in the auth iframe hosted by gaia_auth extension. | |
168 void ExecuteJsInSigninFrame(const std::string& js) { | |
169 content::WebContents* web_contents = | |
170 browser()->tab_strip_model()->GetActiveWebContents(); | |
171 ASSERT_TRUE(content::ExecuteScript(InlineLoginUI::GetAuthIframe( | |
172 web_contents, GURL(), "signin-frame"), js)); | |
173 } | |
174 | |
175 protected: | |
176 FakeGaia fake_gaia_; | |
177 | |
150 private: | 178 private: |
179 virtual void SetUp() OVERRIDE { | |
180 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | |
181 | |
182 // EmbeddedTestServer spawns a thread to initialize socket. | |
183 // Stop IO thread in preparation for fork and exec. | |
184 // embedded_test_server()->StopThread(); | |
guohui
2014/08/07 22:31:23
@xiyuan, your suggested change of splitting the te
xiyuan
2014/08/07 23:07:18
Splitting into two parts is required, per oshima's
| |
185 | |
186 InProcessBrowserTest::SetUp(); | |
187 } | |
188 | |
151 virtual void SetUpOnMainThread() OVERRIDE { | 189 virtual void SetUpOnMainThread() OVERRIDE { |
190 // embedded_test_server()->RestartThreadAndListen(); | |
191 | |
192 embedded_test_server()->RegisterRequestHandler( | |
193 base::Bind(&FakeGaia::HandleRequest, base::Unretained(&fake_gaia_))); | |
194 | |
152 content::WebUIControllerFactory::UnregisterFactoryForTesting( | 195 content::WebUIControllerFactory::UnregisterFactoryForTesting( |
153 ChromeWebUIControllerFactory::GetInstance()); | 196 ChromeWebUIControllerFactory::GetInstance()); |
154 test_factory_.reset(new TestChromeWebUIControllerFactory); | 197 test_factory_.reset(new TestChromeWebUIControllerFactory); |
155 content::WebUIControllerFactory::RegisterFactory(test_factory_.get()); | 198 content::WebUIControllerFactory::RegisterFactory(test_factory_.get()); |
156 test_factory_->AddFactoryOverride( | 199 test_factory_->AddFactoryOverride( |
157 GURL(kFooWebUIURL).host(), &foo_provider_); | 200 GURL(kFooWebUIURL).host(), &foo_provider_); |
158 } | 201 } |
159 | 202 |
160 virtual void TearDownOnMainThread() OVERRIDE { | 203 virtual void TearDownOnMainThread() OVERRIDE { |
161 test_factory_->RemoveFactoryOverride(GURL(kFooWebUIURL).host()); | 204 test_factory_->RemoveFactoryOverride(GURL(kFooWebUIURL).host()); |
162 content::WebUIControllerFactory::UnregisterFactoryForTesting( | 205 content::WebUIControllerFactory::UnregisterFactoryForTesting( |
163 test_factory_.get()); | 206 test_factory_.get()); |
164 test_factory_.reset(); | 207 test_factory_.reset(); |
165 } | 208 } |
166 | 209 |
210 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
211 const GURL& base_url = embedded_test_server()->base_url(); | |
212 command_line->AppendSwitchASCII(::switches::kGaiaUrl, base_url.spec()); | |
213 command_line->AppendSwitchASCII(::switches::kLsoUrl, base_url.spec()); | |
214 command_line->AppendSwitchASCII(::switches::kGoogleApisUrl, | |
215 base_url.spec()); | |
216 fake_gaia_.Initialize(); | |
217 } | |
218 | |
167 FooWebUIProvider foo_provider_; | 219 FooWebUIProvider foo_provider_; |
168 scoped_ptr<TestChromeWebUIControllerFactory> test_factory_; | 220 scoped_ptr<TestChromeWebUIControllerFactory> test_factory_; |
169 }; | 221 }; |
170 | 222 |
171 // Make sure that the foo webui handler is working properly and that it gets | 223 // Make sure that the foo webui handler is working properly and that it gets |
172 // created when navigated to normally. | 224 // created when navigated to normally. |
173 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, Basic) { | 225 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, Basic) { |
174 const GURL kUrl(kFooWebUIURL); | 226 const GURL kUrl(kFooWebUIURL); |
175 EXPECT_CALL(foo_provider(), NewWebUI(_, ::testing::Eq(kUrl))) | 227 EXPECT_CALL(foo_provider(), NewWebUI(_, ::testing::Eq(kUrl))) |
176 .WillOnce(ReturnNewWebUI()); | 228 .WillOnce(ReturnNewWebUI()); |
(...skipping 13 matching lines...) Expand all Loading... | |
190 #if defined(OS_CHROMEOS) | 242 #if defined(OS_CHROMEOS) |
191 #define MAYBE_TopFrameNavigationDisallowed DISABLED_TopFrameNavigationDisallowed | 243 #define MAYBE_TopFrameNavigationDisallowed DISABLED_TopFrameNavigationDisallowed |
192 #else | 244 #else |
193 #define MAYBE_TopFrameNavigationDisallowed TopFrameNavigationDisallowed | 245 #define MAYBE_TopFrameNavigationDisallowed TopFrameNavigationDisallowed |
194 #endif | 246 #endif |
195 | 247 |
196 // Make sure that the gaia iframe cannot trigger top-frame navigation. | 248 // Make sure that the gaia iframe cannot trigger top-frame navigation. |
197 // TODO(guohui): flaky on trybot crbug/364759. | 249 // TODO(guohui): flaky on trybot crbug/364759. |
198 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, | 250 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, |
199 MAYBE_TopFrameNavigationDisallowed) { | 251 MAYBE_TopFrameNavigationDisallowed) { |
200 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | |
201 // Loads into gaia iframe a web page that attempts to deframe on load. | 252 // Loads into gaia iframe a web page that attempts to deframe on load. |
202 GURL deframe_url(embedded_test_server()->GetURL("/login/deframe.html")); | 253 GURL deframe_url(embedded_test_server()->GetURL("/login/deframe.html")); |
203 GURL url(net::AppendOrReplaceQueryParameter( | 254 GURL url(net::AppendOrReplaceQueryParameter( |
204 signin::GetPromoURL(signin::SOURCE_START_PAGE, false), | 255 signin::GetPromoURL(signin::SOURCE_START_PAGE, false), |
205 "frameUrl", deframe_url.spec())); | 256 "frameUrl", deframe_url.spec())); |
206 ui_test_utils::NavigateToURL(browser(), url); | 257 ui_test_utils::NavigateToURL(browser(), url); |
207 WaitUntilUIReady(); | 258 WaitUntilUIReady(); |
208 | 259 |
209 content::WebContents* contents = | 260 content::WebContents* contents = |
210 browser()->tab_strip_model()->GetActiveWebContents(); | 261 browser()->tab_strip_model()->GetActiveWebContents(); |
(...skipping 21 matching lines...) Expand all Loading... | |
232 content::WebContents* contents = | 283 content::WebContents* contents = |
233 browser()->tab_strip_model()->GetActiveWebContents(); | 284 browser()->tab_strip_model()->GetActiveWebContents(); |
234 ASSERT_TRUE(content::ExecuteScript( | 285 ASSERT_TRUE(content::ExecuteScript( |
235 contents, "window.location.href = 'chrome://foo'")); | 286 contents, "window.location.href = 'chrome://foo'")); |
236 | 287 |
237 content::TestNavigationObserver navigation_observer(contents, 1); | 288 content::TestNavigationObserver navigation_observer(contents, 1); |
238 navigation_observer.Wait(); | 289 navigation_observer.Wait(); |
239 | 290 |
240 EXPECT_EQ(GURL("about:blank"), contents->GetVisibleURL()); | 291 EXPECT_EQ(GURL("about:blank"), contents->GetVisibleURL()); |
241 } | 292 } |
293 | |
294 #if !defined(OS_CHROMEOS) | |
295 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, | |
296 ConfirmationRequiredForNonsecureSignin) { | |
297 fake_gaia_.SetFakeMergeSessionParamsForEmail("email"); | |
298 | |
299 // Navigates to the Chrome signin page which loads the fake gaia auth page. | |
300 // Since the fake gaia auth page is served over HTTP, thus expects to see an | |
301 // untrusted signin confirmation dialog upon submitting credentials below. | |
302 ui_test_utils::NavigateToURL( | |
303 browser(), signin::GetPromoURL(signin::SOURCE_START_PAGE, false)); | |
304 WaitUntilUIReady(); | |
305 | |
306 MockLoginUIObserver observer; | |
307 LoginUIServiceFactory::GetForProfile(browser()->profile()) | |
308 ->AddObserver(&observer); | |
309 base::RunLoop run_loop; | |
310 EXPECT_CALL(observer, OnUntrustedLoginUIShown()) | |
311 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | |
312 | |
313 content::WebContents* contents = | |
314 browser()->tab_strip_model()->GetActiveWebContents(); | |
315 std::string js = | |
316 "document.getElementById('Email').value = 'email';" | |
317 "document.getElementById('Passwd').value = 'password';" | |
318 "document.getElementById('signIn').click();"; | |
319 ExecuteJsInSigninFrame(js); | |
320 | |
321 run_loop.Run(); | |
322 base::MessageLoop::current()->RunUntilIdle(); | |
323 } | |
324 #endif // OS_CHROMEOS | |
OLD | NEW |