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

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

Issue 134263005: Implement inline signin with iframe (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Test for no webui in iframe Created 6 years, 10 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
« no previous file with comments | « chrome/browser/ui/webui/signin/inline_login_ui.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/signin/signin_promo.h"
6 #include "chrome/browser/ui/browser.h"
7 #include "chrome/browser/ui/tabs/tab_strip_model.h"
8 #include "chrome/common/chrome_switches.h"
9 #include "chrome/common/url_constants.h"
10 #include "chrome/test/base/in_process_browser_test.h"
11 #include "chrome/test/base/test_chrome_web_ui_controller_factory.h"
12 #include "chrome/test/base/testing_browser_process.h"
13 #include "chrome/test/base/ui_test_utils.h"
14 #include "content/public/browser/render_process_host.h"
15 #include "content/public/browser/session_storage_namespace.h"
16 #include "content/public/browser/storage_partition.h"
17 #include "content/public/browser/web_contents.h"
18 #include "content/public/browser/web_ui_controller.h"
19 #include "content/public/common/url_constants.h"
20 #include "content/public/test/browser_test_utils.h"
21 #include "testing/gmock/include/gmock/gmock.h"
22 #include "testing/gtest/include/gtest/gtest.h"
23
24 using ::testing::_;
25
26 namespace {
27
28 struct ContentInfo {
29 ContentInfo(int pid, content::StoragePartition* storage_partition) {
30 this->pid = pid;
31 this->storage_partition = storage_partition;
32 }
33
34 int pid;
35 content::StoragePartition* storage_partition;
36 };
37
38 ContentInfo NavigateAndGetInfo(
39 Browser* browser,
40 const GURL& url,
41 WindowOpenDisposition disposition) {
42 ui_test_utils::NavigateToURLWithDisposition(
43 browser, url, disposition,
44 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
45 content::WebContents* contents =
46 browser->tab_strip_model()->GetActiveWebContents();
47 content::RenderProcessHost* process = contents->GetRenderProcessHost();
48 return ContentInfo(process->GetID(), process->GetStoragePartition());
49 }
50
51 // Returns a new WebUI object for the WebContents from |arg0|.
52 ACTION(ReturnNewWebUI) {
53 return new content::WebUIController(arg0);
54 }
55
56 // Mock the TestChromeWebUIControllerFactory::WebUIProvider to prove that we are
57 // not called as expected.
58 class FooWebUIProvider
59 : public TestChromeWebUIControllerFactory::WebUIProvider {
60 public:
61 MOCK_METHOD2(NewWebUI, content::WebUIController*(content::WebUI* web_ui,
62 const GURL& url));
63 };
64
65 const char kFooWebUIURL[] = "chrome://foo/";
66
67 } // namespace
68
69 class InlineLoginUIBrowserTest : public InProcessBrowserTest {
70 public:
71 InlineLoginUIBrowserTest() {}
72 };
73
74 IN_PROC_BROWSER_TEST_F(InlineLoginUIBrowserTest, DifferentStorageId) {
75 GURL test_url = ui_test_utils::GetTestUrl(
76 base::FilePath(base::FilePath::kCurrentDirectory),
77 base::FilePath(FILE_PATH_LITERAL("title1.html")));
78
79 ContentInfo info1 =
80 NavigateAndGetInfo(browser(), test_url, CURRENT_TAB);
81 ContentInfo info2 =
82 NavigateAndGetInfo(browser(),
83 signin::GetPromoURL(signin::SOURCE_START_PAGE, false),
84 CURRENT_TAB);
85 ContentInfo info3 =
86 NavigateAndGetInfo(browser(), test_url, CURRENT_TAB);
87 ContentInfo info4 =
88 NavigateAndGetInfo(browser(),
89 signin::GetPromoURL( signin::SOURCE_START_PAGE, false),
90 NEW_FOREGROUND_TAB);
91
92 // The info for test_url should be the same.
93 ASSERT_EQ(info1.storage_partition, info3.storage_partition);
94 // The info for signin should be the same.
95 ASSERT_EQ(info2.storage_partition, info4.storage_partition);
96 // The info for test_url and signin should be different.
97 ASSERT_NE(info1.storage_partition, info2.storage_partition);
98 }
99
100 IN_PROC_BROWSER_TEST_F(InlineLoginUIBrowserTest, OneProcessLimit) {
101 GURL test_url_1 = ui_test_utils::GetTestUrl(
102 base::FilePath(base::FilePath::kCurrentDirectory),
103 base::FilePath(FILE_PATH_LITERAL("title1.html")));
104 GURL test_url_2 = ui_test_utils::GetTestUrl(
105 base::FilePath(base::FilePath::kCurrentDirectory),
106 base::FilePath(FILE_PATH_LITERAL("data:text/html,Hello world!")));
107
108 // Even when the process limit is set to one, the signin process should
109 // still be given its own process and storage partition.
110 content::RenderProcessHost::SetMaxRendererProcessCount(1);
111
112 ContentInfo info1 =
113 NavigateAndGetInfo(browser(), test_url_1, CURRENT_TAB);
114 ContentInfo info2 =
115 NavigateAndGetInfo(browser(), test_url_2, CURRENT_TAB);
116 ContentInfo info3 =
117 NavigateAndGetInfo(browser(),
118 signin::GetPromoURL( signin::SOURCE_START_PAGE, false),
119 CURRENT_TAB);
120
121 ASSERT_EQ(info1.pid, info2.pid);
122 ASSERT_NE(info1.pid, info3.pid);
123 }
124
125 class InlineLoginUISafeIframeBrowserTest : public InProcessBrowserTest {
126 public:
127 FooWebUIProvider& foo_provider() { return foo_provider_; }
128
129 private:
130 virtual void SetUpOnMainThread() OVERRIDE {
131 content::WebUIControllerFactory::UnregisterFactoryForTesting(
132 ChromeWebUIControllerFactory::GetInstance());
133 test_factory_.reset(new TestChromeWebUIControllerFactory);
134 content::WebUIControllerFactory::RegisterFactory(test_factory_.get());
135 test_factory_->AddFactoryOverride(
136 GURL(kFooWebUIURL).host(), &foo_provider_);
137 }
138
139 virtual void CleanUpOnMainThread() OVERRIDE {
140 test_factory_->RemoveFactoryOverride(GURL(kFooWebUIURL).host());
141 content::WebUIControllerFactory::UnregisterFactoryForTesting(
142 test_factory_.get());
143 test_factory_.reset();
144 }
145
146 FooWebUIProvider foo_provider_;
147 scoped_ptr<TestChromeWebUIControllerFactory> test_factory_;
148 };
149
150 // Make sure that the foo webui handler is working properly and that it gets
151 // created when navigated to nromally.
jam 2014/02/14 23:45:14 nit: normally
Roger Tawa OOO till Jul 10th 2014/02/15 00:48:47 Yup :-) fixed in patchset 15
152 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, Basic) {
153 const GURL kUrl(kFooWebUIURL);
154 EXPECT_CALL(foo_provider(), NewWebUI(_, ::testing::Eq(kUrl)))
155 .WillOnce(ReturnNewWebUI());
156 ui_test_utils::NavigateToURL(browser(), GURL(kFooWebUIURL));
157 }
158
159 // Make sure that the foo webui handler does not get created when we try to
160 // load it inside the iframe of the login ui.
161 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, NoWebUIInIframe) {
162 GURL url = signin::GetPromoURL(signin::SOURCE_START_PAGE, false).
163 Resolve("?source=0&frameUrl=chrome://foo");
164 EXPECT_CALL(foo_provider(), NewWebUI(_, _)).Times(0);
165 ui_test_utils::NavigateToURL(browser(), url);
166 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/signin/inline_login_ui.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698