Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: chrome/browser/ui/webui/signin/inline_login_ui_browsertest.cc

Issue 418043002: Add test for showing confirmation dialog for unsecure signin (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix isolate dependency Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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
150 private: 175 private:
176 virtual void SetUp() OVERRIDE {
177 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
178
179 // EmbeddedTestServer spawns a thread to initialize socket.
180 // Stop IO thread in preparation for fork and exec.
181 embedded_test_server()->StopThread();
182
183 InProcessBrowserTest::SetUp();
184 }
185
186 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
187 const GURL& base_url = embedded_test_server()->base_url();
188 command_line->AppendSwitchASCII(::switches::kGaiaUrl, base_url.spec());
189 command_line->AppendSwitchASCII(::switches::kLsoUrl, base_url.spec());
190 command_line->AppendSwitchASCII(::switches::kGoogleApisUrl,
191 base_url.spec());
192 }
193
151 virtual void SetUpOnMainThread() OVERRIDE { 194 virtual void SetUpOnMainThread() OVERRIDE {
195 embedded_test_server()->RestartThreadAndListen();
196
152 content::WebUIControllerFactory::UnregisterFactoryForTesting( 197 content::WebUIControllerFactory::UnregisterFactoryForTesting(
153 ChromeWebUIControllerFactory::GetInstance()); 198 ChromeWebUIControllerFactory::GetInstance());
154 test_factory_.reset(new TestChromeWebUIControllerFactory); 199 test_factory_.reset(new TestChromeWebUIControllerFactory);
155 content::WebUIControllerFactory::RegisterFactory(test_factory_.get()); 200 content::WebUIControllerFactory::RegisterFactory(test_factory_.get());
156 test_factory_->AddFactoryOverride( 201 test_factory_->AddFactoryOverride(
157 GURL(kFooWebUIURL).host(), &foo_provider_); 202 GURL(kFooWebUIURL).host(), &foo_provider_);
158 } 203 }
159 204
160 virtual void TearDownOnMainThread() OVERRIDE { 205 virtual void TearDownOnMainThread() OVERRIDE {
161 test_factory_->RemoveFactoryOverride(GURL(kFooWebUIURL).host()); 206 test_factory_->RemoveFactoryOverride(GURL(kFooWebUIURL).host());
162 content::WebUIControllerFactory::UnregisterFactoryForTesting( 207 content::WebUIControllerFactory::UnregisterFactoryForTesting(
163 test_factory_.get()); 208 test_factory_.get());
164 test_factory_.reset(); 209 test_factory_.reset();
210 EXPECT_TRUE(embedded_test_server()->ShutdownAndWaitUntilComplete());
165 } 211 }
166 212
167 FooWebUIProvider foo_provider_; 213 FooWebUIProvider foo_provider_;
168 scoped_ptr<TestChromeWebUIControllerFactory> test_factory_; 214 scoped_ptr<TestChromeWebUIControllerFactory> test_factory_;
169 }; 215 };
170 216
171 // Make sure that the foo webui handler is working properly and that it gets 217 // Make sure that the foo webui handler is working properly and that it gets
172 // created when navigated to normally. 218 // created when navigated to normally.
173 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, Basic) { 219 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, Basic) {
174 const GURL kUrl(kFooWebUIURL); 220 const GURL kUrl(kFooWebUIURL);
(...skipping 15 matching lines...) Expand all
190 #if defined(OS_CHROMEOS) 236 #if defined(OS_CHROMEOS)
191 #define MAYBE_TopFrameNavigationDisallowed DISABLED_TopFrameNavigationDisallowed 237 #define MAYBE_TopFrameNavigationDisallowed DISABLED_TopFrameNavigationDisallowed
192 #else 238 #else
193 #define MAYBE_TopFrameNavigationDisallowed TopFrameNavigationDisallowed 239 #define MAYBE_TopFrameNavigationDisallowed TopFrameNavigationDisallowed
194 #endif 240 #endif
195 241
196 // Make sure that the gaia iframe cannot trigger top-frame navigation. 242 // Make sure that the gaia iframe cannot trigger top-frame navigation.
197 // TODO(guohui): flaky on trybot crbug/364759. 243 // TODO(guohui): flaky on trybot crbug/364759.
198 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, 244 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest,
199 MAYBE_TopFrameNavigationDisallowed) { 245 MAYBE_TopFrameNavigationDisallowed) {
200 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
201 // Loads into gaia iframe a web page that attempts to deframe on load. 246 // Loads into gaia iframe a web page that attempts to deframe on load.
202 GURL deframe_url(embedded_test_server()->GetURL("/login/deframe.html")); 247 GURL deframe_url(embedded_test_server()->GetURL("/login/deframe.html"));
203 GURL url(net::AppendOrReplaceQueryParameter( 248 GURL url(net::AppendOrReplaceQueryParameter(
204 signin::GetPromoURL(signin::SOURCE_START_PAGE, false), 249 signin::GetPromoURL(signin::SOURCE_START_PAGE, false),
205 "frameUrl", deframe_url.spec())); 250 "frameUrl", deframe_url.spec()));
206 ui_test_utils::NavigateToURL(browser(), url); 251 ui_test_utils::NavigateToURL(browser(), url);
207 WaitUntilUIReady(); 252 WaitUntilUIReady();
208 253
209 content::WebContents* contents = 254 content::WebContents* contents =
210 browser()->tab_strip_model()->GetActiveWebContents(); 255 browser()->tab_strip_model()->GetActiveWebContents();
(...skipping 21 matching lines...) Expand all
232 content::WebContents* contents = 277 content::WebContents* contents =
233 browser()->tab_strip_model()->GetActiveWebContents(); 278 browser()->tab_strip_model()->GetActiveWebContents();
234 ASSERT_TRUE(content::ExecuteScript( 279 ASSERT_TRUE(content::ExecuteScript(
235 contents, "window.location.href = 'chrome://foo'")); 280 contents, "window.location.href = 'chrome://foo'"));
236 281
237 content::TestNavigationObserver navigation_observer(contents, 1); 282 content::TestNavigationObserver navigation_observer(contents, 1);
238 navigation_observer.Wait(); 283 navigation_observer.Wait();
239 284
240 EXPECT_EQ(GURL("about:blank"), contents->GetVisibleURL()); 285 EXPECT_EQ(GURL("about:blank"), contents->GetVisibleURL());
241 } 286 }
287
288 #if !defined(OS_CHROMEOS)
289 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest,
290 ConfirmationRequiredForNonsecureSignin) {
291 FakeGaia fake_gaia;
292 fake_gaia.Initialize();
293
294 embedded_test_server()->RegisterRequestHandler(
295 base::Bind(&FakeGaia::HandleRequest,
296 base::Unretained(&fake_gaia)));
297 fake_gaia.SetFakeMergeSessionParams(
298 "email", "fake-sid-cookie", "fake-lsid-cookie");
299
300 // Navigates to the Chrome signin page which loads the fake gaia auth page.
301 // Since the fake gaia auth page is served over HTTP, thus expects to see an
302 // untrusted signin confirmation dialog upon submitting credentials below.
303 ui_test_utils::NavigateToURL(
304 browser(), signin::GetPromoURL(signin::SOURCE_START_PAGE, false));
305 WaitUntilUIReady();
306
307 MockLoginUIObserver observer;
308 LoginUIServiceFactory::GetForProfile(browser()->profile())
309 ->AddObserver(&observer);
310 base::RunLoop run_loop;
311 EXPECT_CALL(observer, OnUntrustedLoginUIShown())
312 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
313
314 std::string js =
315 "document.getElementById('Email').value = 'email';"
316 "document.getElementById('Passwd').value = 'password';"
317 "document.getElementById('signIn').click();";
318 ExecuteJsInSigninFrame(js);
319
320 run_loop.Run();
321 base::MessageLoop::current()->RunUntilIdle();
322 }
323 #endif // OS_CHROMEOS
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/signin/inline_login_handler_impl.cc ('k') | chrome/browser/ui/webui/signin/login_ui_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698