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

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

Issue 807503004: While trying to enable webview sign-in by default, I found a bunch of issues (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move comment, remove RunAllPending Created 5 years, 11 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
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 "base/command_line.h"
6 #include "chrome/browser/signin/signin_promo.h" 6 #include "chrome/browser/signin/signin_promo.h"
7 #include "chrome/browser/ui/browser.h" 7 #include "chrome/browser/ui/browser.h"
8 #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" 9 #include "chrome/browser/ui/webui/signin/inline_login_ui.h"
10 #include "chrome/browser/ui/webui/signin/login_ui_service.h" 10 #include "chrome/browser/ui/webui/signin/login_ui_service.h"
11 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" 11 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
12 #include "chrome/browser/ui/webui/signin/login_ui_test_utils.h" 12 #include "chrome/browser/ui/webui/signin/login_ui_test_utils.h"
13 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
14 #include "chrome/common/url_constants.h" 14 #include "chrome/common/url_constants.h"
15 #include "chrome/test/base/in_process_browser_test.h" 15 #include "chrome/test/base/in_process_browser_test.h"
16 #include "chrome/test/base/test_browser_window.h" 16 #include "chrome/test/base/test_browser_window.h"
17 #include "chrome/test/base/test_chrome_web_ui_controller_factory.h" 17 #include "chrome/test/base/test_chrome_web_ui_controller_factory.h"
18 #include "chrome/test/base/testing_browser_process.h" 18 #include "chrome/test/base/testing_browser_process.h"
19 #include "chrome/test/base/ui_test_utils.h" 19 #include "chrome/test/base/ui_test_utils.h"
20 #include "components/signin/core/common/profile_management_switches.h"
20 #include "content/public/browser/render_frame_host.h" 21 #include "content/public/browser/render_frame_host.h"
21 #include "content/public/browser/render_process_host.h" 22 #include "content/public/browser/render_process_host.h"
22 #include "content/public/browser/session_storage_namespace.h" 23 #include "content/public/browser/session_storage_namespace.h"
23 #include "content/public/browser/storage_partition.h" 24 #include "content/public/browser/storage_partition.h"
24 #include "content/public/browser/web_contents.h" 25 #include "content/public/browser/web_contents.h"
25 #include "content/public/browser/web_ui_controller.h" 26 #include "content/public/browser/web_ui_controller.h"
26 #include "content/public/common/url_constants.h" 27 #include "content/public/common/url_constants.h"
27 #include "content/public/test/browser_test_utils.h" 28 #include "content/public/test/browser_test_utils.h"
28 #include "content/public/test/test_navigation_observer.h" 29 #include "content/public/test/test_navigation_observer.h"
30 #include "extensions/browser/guest_view/guest_view_manager.h"
29 #include "google_apis/gaia/fake_gaia.h" 31 #include "google_apis/gaia/fake_gaia.h"
30 #include "google_apis/gaia/gaia_switches.h" 32 #include "google_apis/gaia/gaia_switches.h"
31 #include "net/base/url_util.h" 33 #include "net/base/url_util.h"
32 #include "net/test/embedded_test_server/embedded_test_server.h" 34 #include "net/test/embedded_test_server/embedded_test_server.h"
33 #include "net/test/embedded_test_server/http_request.h" 35 #include "net/test/embedded_test_server/http_request.h"
34 #include "net/test/embedded_test_server/http_response.h" 36 #include "net/test/embedded_test_server/http_response.h"
35 #include "testing/gmock/include/gmock/gmock.h" 37 #include "testing/gmock/include/gmock/gmock.h"
36 #include "testing/gtest/include/gtest/gtest.h" 38 #include "testing/gtest/include/gtest/gtest.h"
37 39
38 using ::testing::_; 40 using ::testing::_;
39 using ::testing::Invoke; 41 using ::testing::Invoke;
40 using ::testing::InvokeWithoutArgs; 42 using ::testing::InvokeWithoutArgs;
41 43
42 using login_ui_test_utils::ExecuteJsToSigninInSigninFrame; 44 using login_ui_test_utils::ExecuteJsToSigninInSigninFrame;
43 using login_ui_test_utils::WaitUntilUIReady; 45 using login_ui_test_utils::WaitUntilUIReady;
44 46
45 namespace { 47 namespace {
46 48
47 struct ContentInfo { 49 struct ContentInfo {
48 ContentInfo(int pid, content::StoragePartition* storage_partition) { 50 ContentInfo(content::WebContents* contents,
51 int pid,
52 content::StoragePartition* storage_partition) {
53 this->contents = contents;
49 this->pid = pid; 54 this->pid = pid;
50 this->storage_partition = storage_partition; 55 this->storage_partition = storage_partition;
51 } 56 }
52 57
58 content::WebContents* contents;
53 int pid; 59 int pid;
54 content::StoragePartition* storage_partition; 60 content::StoragePartition* storage_partition;
55 }; 61 };
56 62
57 ContentInfo NavigateAndGetInfo( 63 ContentInfo NavigateAndGetInfo(
58 Browser* browser, 64 Browser* browser,
59 const GURL& url, 65 const GURL& url,
60 WindowOpenDisposition disposition) { 66 WindowOpenDisposition disposition) {
61 ui_test_utils::NavigateToURLWithDisposition( 67 ui_test_utils::NavigateToURLWithDisposition(
62 browser, url, disposition, 68 browser, url, disposition,
63 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 69 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
64 content::WebContents* contents = 70 content::WebContents* contents =
65 browser->tab_strip_model()->GetActiveWebContents(); 71 browser->tab_strip_model()->GetActiveWebContents();
66 content::RenderProcessHost* process = contents->GetRenderProcessHost(); 72 content::RenderProcessHost* process = contents->GetRenderProcessHost();
67 return ContentInfo(process->GetID(), process->GetStoragePartition()); 73 return ContentInfo(contents, process->GetID(),
74 process->GetStoragePartition());
68 } 75 }
69 76
70 // Returns a new WebUI object for the WebContents from |arg0|. 77 // Returns a new WebUI object for the WebContents from |arg0|.
71 ACTION(ReturnNewWebUI) { 78 ACTION(ReturnNewWebUI) {
72 return new content::WebUIController(arg0); 79 return new content::WebUIController(arg0);
73 } 80 }
74 81
75 // Mock the TestChromeWebUIControllerFactory::WebUIProvider to prove that we are 82 // Mock the TestChromeWebUIControllerFactory::WebUIProvider to prove that we are
76 // not called as expected. 83 // not called as expected.
77 class FooWebUIProvider 84 class FooWebUIProvider
78 : public TestChromeWebUIControllerFactory::WebUIProvider { 85 : public TestChromeWebUIControllerFactory::WebUIProvider {
79 public: 86 public:
80 MOCK_METHOD2(NewWebUI, content::WebUIController*(content::WebUI* web_ui, 87 MOCK_METHOD2(NewWebUI, content::WebUIController*(content::WebUI* web_ui,
81 const GURL& url)); 88 const GURL& url));
82 }; 89 };
83 90
84 class MockLoginUIObserver : public LoginUIService::Observer { 91 class MockLoginUIObserver : public LoginUIService::Observer {
85 public: 92 public:
86 MOCK_METHOD0(OnUntrustedLoginUIShown, void()); 93 MOCK_METHOD0(OnUntrustedLoginUIShown, void());
87 }; 94 };
88 95
89 const char kFooWebUIURL[] = "chrome://foo/"; 96 const char kFooWebUIURL[] = "chrome://foo/";
90 97
98 bool AddToSet(std::set<content::WebContents*>* set,
99 content::WebContents* web_contents) {
100 set->insert(web_contents);
101 return false;
102 }
103
91 } // namespace 104 } // namespace
92 105
93 class InlineLoginUIBrowserTest : public InProcessBrowserTest { 106 class InlineLoginUIBrowserTest : public InProcessBrowserTest {
94 public: 107 public:
95 InlineLoginUIBrowserTest() {} 108 InlineLoginUIBrowserTest() {}
96 }; 109 };
97 110
98 #if defined(OS_LINUX) || defined(OS_WIN) 111 #if defined(OS_LINUX) || defined(OS_WIN)
99 // crbug.com/422868 112 // crbug.com/422868
100 #define MAYBE_DifferentStorageId DISABLED_DifferentStorageId 113 #define MAYBE_DifferentStorageId DISABLED_DifferentStorageId
101 #else 114 #else
102 #define MAYBE_DifferentStorageId DifferentStorageId 115 #define MAYBE_DifferentStorageId DifferentStorageId
103 #endif 116 #endif
104 IN_PROC_BROWSER_TEST_F(InlineLoginUIBrowserTest, MAYBE_DifferentStorageId) { 117 IN_PROC_BROWSER_TEST_F(InlineLoginUIBrowserTest, MAYBE_DifferentStorageId) {
105 GURL test_url = ui_test_utils::GetTestUrl( 118 if (switches::IsEnableWebviewBasedSignin()) {
106 base::FilePath(base::FilePath::kCurrentDirectory), 119 ContentInfo info = NavigateAndGetInfo(
107 base::FilePath(FILE_PATH_LITERAL("title1.html"))); 120 browser(),
121 signin::GetPromoURL(signin_metrics::SOURCE_START_PAGE, false),
122 CURRENT_TAB);
123 WaitUntilUIReady(browser());
108 124
109 ContentInfo info1 = 125 // Make sure storage partition of embedded webview is different from
110 NavigateAndGetInfo(browser(), test_url, CURRENT_TAB); 126 // parent.
111 ContentInfo info2 = NavigateAndGetInfo( 127 std::set<content::WebContents*> set;
112 browser(), 128 extensions::GuestViewManager* manager =
113 signin::GetPromoURL(signin_metrics::SOURCE_START_PAGE, false), 129 extensions::GuestViewManager::FromBrowserContext(
114 CURRENT_TAB); 130 info.contents->GetBrowserContext());
115 NavigateAndGetInfo(browser(), test_url, CURRENT_TAB); 131 manager->ForEachGuest(info.contents, base::Bind(&AddToSet, &set));
116 ContentInfo info3 = NavigateAndGetInfo( 132 ASSERT_EQ(1u, set.size());
117 browser(), 133 content::WebContents* webview_contents = *set.begin();
118 signin::GetPromoURL(signin_metrics::SOURCE_START_PAGE, false), 134 content::RenderProcessHost* process =
119 NEW_FOREGROUND_TAB); 135 webview_contents->GetRenderProcessHost();
136 ASSERT_NE(info.pid, process->GetID());
137 ASSERT_NE(info.storage_partition, process->GetStoragePartition());
138 } else {
139 GURL test_url = ui_test_utils::GetTestUrl(
140 base::FilePath(base::FilePath::kCurrentDirectory),
141 base::FilePath(FILE_PATH_LITERAL("title1.html")));
120 142
121 // The info for signin should be the same. 143 ContentInfo info1 =
122 ASSERT_EQ(info2.storage_partition, info3.storage_partition); 144 NavigateAndGetInfo(browser(), test_url, CURRENT_TAB);
123 // The info for test_url and signin should be different. 145 ContentInfo info2 = NavigateAndGetInfo(
124 ASSERT_NE(info1.storage_partition, info2.storage_partition); 146 browser(),
147 signin::GetPromoURL(signin_metrics::SOURCE_START_PAGE, false),
148 CURRENT_TAB);
149 NavigateAndGetInfo(browser(), test_url, CURRENT_TAB);
150 ContentInfo info3 = NavigateAndGetInfo(
151 browser(),
152 signin::GetPromoURL(signin_metrics::SOURCE_START_PAGE, false),
153 NEW_FOREGROUND_TAB);
154
155 // The info for signin should be the same.
156 ASSERT_EQ(info2.storage_partition, info3.storage_partition);
157 // The info for test_url and signin should be different.
158 ASSERT_NE(info1.storage_partition, info2.storage_partition);
159 }
125 } 160 }
126 161
127 IN_PROC_BROWSER_TEST_F(InlineLoginUIBrowserTest, OneProcessLimit) { 162 IN_PROC_BROWSER_TEST_F(InlineLoginUIBrowserTest, OneProcessLimit) {
128 GURL test_url_1 = ui_test_utils::GetTestUrl( 163 GURL test_url_1 = ui_test_utils::GetTestUrl(
129 base::FilePath(base::FilePath::kCurrentDirectory), 164 base::FilePath(base::FilePath::kCurrentDirectory),
130 base::FilePath(FILE_PATH_LITERAL("title1.html"))); 165 base::FilePath(FILE_PATH_LITERAL("title1.html")));
131 GURL test_url_2 = ui_test_utils::GetTestUrl( 166 GURL test_url_2 = ui_test_utils::GetTestUrl(
132 base::FilePath(base::FilePath::kCurrentDirectory), 167 base::FilePath(base::FilePath::kCurrentDirectory),
133 base::FilePath(FILE_PATH_LITERAL("data:text/html,Hello world!"))); 168 base::FilePath(FILE_PATH_LITERAL("data:text/html,Hello world!")));
134 169
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 #if !defined(OS_CHROMEOS) 305 #if !defined(OS_CHROMEOS)
271 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, 306 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest,
272 ConfirmationRequiredForNonsecureSignin) { 307 ConfirmationRequiredForNonsecureSignin) {
273 FakeGaia fake_gaia; 308 FakeGaia fake_gaia;
274 fake_gaia.Initialize(); 309 fake_gaia.Initialize();
275 310
276 embedded_test_server()->RegisterRequestHandler( 311 embedded_test_server()->RegisterRequestHandler(
277 base::Bind(&FakeGaia::HandleRequest, 312 base::Bind(&FakeGaia::HandleRequest,
278 base::Unretained(&fake_gaia))); 313 base::Unretained(&fake_gaia)));
279 fake_gaia.SetFakeMergeSessionParams( 314 fake_gaia.SetFakeMergeSessionParams(
280 "email", "fake-sid-cookie", "fake-lsid-cookie"); 315 "email@gmail.com", "fake-sid-cookie", "fake-lsid-cookie");
281 316
282 // Navigates to the Chrome signin page which loads the fake gaia auth page. 317 // Navigates to the Chrome signin page which loads the fake gaia auth page.
283 // Since the fake gaia auth page is served over HTTP, thus expects to see an 318 // Since the fake gaia auth page is served over HTTP, thus expects to see an
284 // untrusted signin confirmation dialog upon submitting credentials below. 319 // untrusted signin confirmation dialog upon submitting credentials below.
285 ui_test_utils::NavigateToURL( 320 ui_test_utils::NavigateToURL(
286 browser(), signin::GetPromoURL(signin_metrics::SOURCE_START_PAGE, false)); 321 browser(), signin::GetPromoURL(signin_metrics::SOURCE_START_PAGE, false));
287 WaitUntilUIReady(browser()); 322 WaitUntilUIReady(browser());
288 323
289 MockLoginUIObserver observer; 324 MockLoginUIObserver observer;
290 LoginUIServiceFactory::GetForProfile(browser()->profile()) 325 LoginUIServiceFactory::GetForProfile(browser()->profile())
291 ->AddObserver(&observer); 326 ->AddObserver(&observer);
292 base::RunLoop run_loop; 327 base::RunLoop run_loop;
293 EXPECT_CALL(observer, OnUntrustedLoginUIShown()) 328 EXPECT_CALL(observer, OnUntrustedLoginUIShown())
294 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 329 .WillOnce(InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
295 330
296 ExecuteJsToSigninInSigninFrame(browser(), "email", "password"); 331 ExecuteJsToSigninInSigninFrame(browser(), "email@gmail.com", "password");
297 run_loop.Run(); 332 run_loop.Run();
298 base::MessageLoop::current()->RunUntilIdle(); 333 base::MessageLoop::current()->RunUntilIdle();
299 } 334 }
300 #endif // OS_CHROMEOS 335 #endif // OS_CHROMEOS
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698