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

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

Issue 239143009: Disallow top-level navigation in gaia iframe (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: undo cros change Created 6 years, 8 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 "chrome/browser/signin/signin_promo.h" 5 #include "chrome/browser/signin/signin_promo.h"
6 #include "chrome/browser/ui/browser.h" 6 #include "chrome/browser/ui/browser.h"
7 #include "chrome/browser/ui/tabs/tab_strip_model.h" 7 #include "chrome/browser/ui/tabs/tab_strip_model.h"
8 #include "chrome/common/chrome_switches.h" 8 #include "chrome/common/chrome_switches.h"
9 #include "chrome/common/url_constants.h" 9 #include "chrome/common/url_constants.h"
10 #include "chrome/test/base/in_process_browser_test.h" 10 #include "chrome/test/base/in_process_browser_test.h"
11 #include "chrome/test/base/test_chrome_web_ui_controller_factory.h" 11 #include "chrome/test/base/test_chrome_web_ui_controller_factory.h"
12 #include "chrome/test/base/testing_browser_process.h" 12 #include "chrome/test/base/testing_browser_process.h"
13 #include "chrome/test/base/ui_test_utils.h" 13 #include "chrome/test/base/ui_test_utils.h"
14 #include "content/public/browser/render_process_host.h" 14 #include "content/public/browser/render_process_host.h"
15 #include "content/public/browser/session_storage_namespace.h" 15 #include "content/public/browser/session_storage_namespace.h"
16 #include "content/public/browser/storage_partition.h" 16 #include "content/public/browser/storage_partition.h"
17 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
18 #include "content/public/browser/web_ui_controller.h" 18 #include "content/public/browser/web_ui_controller.h"
19 #include "content/public/common/url_constants.h" 19 #include "content/public/common/url_constants.h"
20 #include "content/public/test/browser_test_utils.h" 20 #include "content/public/test/browser_test_utils.h"
21 #include "net/base/url_util.h"
22 #include "net/test/embedded_test_server/embedded_test_server.h"
21 #include "testing/gmock/include/gmock/gmock.h" 23 #include "testing/gmock/include/gmock/gmock.h"
22 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
23 25
24 using ::testing::_; 26 using ::testing::_;
25 27
26 namespace { 28 namespace {
27 29
28 struct ContentInfo { 30 struct ContentInfo {
29 ContentInfo(int pid, content::StoragePartition* storage_partition) { 31 ContentInfo(int pid, content::StoragePartition* storage_partition) {
30 this->pid = pid; 32 this->pid = pid;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 CURRENT_TAB); 118 CURRENT_TAB);
117 119
118 ASSERT_EQ(info1.pid, info2.pid); 120 ASSERT_EQ(info1.pid, info2.pid);
119 ASSERT_NE(info1.pid, info3.pid); 121 ASSERT_NE(info1.pid, info3.pid);
120 } 122 }
121 123
122 class InlineLoginUISafeIframeBrowserTest : public InProcessBrowserTest { 124 class InlineLoginUISafeIframeBrowserTest : public InProcessBrowserTest {
123 public: 125 public:
124 FooWebUIProvider& foo_provider() { return foo_provider_; } 126 FooWebUIProvider& foo_provider() { return foo_provider_; }
125 127
128 void WaitUntilUIReady() {
129 // TODO(guohui): fix the logic below for CrOS.
130 #if !defined(OS_CHROMEOS)
131 ASSERT_TRUE(content::ExecuteScript(
132 browser()->tab_strip_model()->GetActiveWebContents(),
133 "if (!inline.login.getAuthExtHost())"
134 " inline.login.initialize();"
135 "inline.login.getAuthExtHost().addEventListener('ready', function() {"
136 " window.domAutomationController.setAutomationId(0);"
137 " window.domAutomationController.send('ready');"
138 "});"));
139
140 content::DOMMessageQueue message_queue;
141 std::string message;
142 ASSERT_TRUE(message_queue.WaitForMessage(&message));
xiyuan 2014/04/17 15:04:15 This is could timeout when 'ready' event is alread
guohui 2014/04/17 15:08:31 it seems on cros ready event is fired upon receivi
guohui 2014/04/17 15:28:49 as clarified over chat, xiyuan is right, on deskto
143 EXPECT_EQ("\"ready\"", message);
144 #endif // OS_CHROMEOS
145 }
146
126 private: 147 private:
127 virtual void SetUpOnMainThread() OVERRIDE { 148 virtual void SetUpOnMainThread() OVERRIDE {
128 content::WebUIControllerFactory::UnregisterFactoryForTesting( 149 content::WebUIControllerFactory::UnregisterFactoryForTesting(
129 ChromeWebUIControllerFactory::GetInstance()); 150 ChromeWebUIControllerFactory::GetInstance());
130 test_factory_.reset(new TestChromeWebUIControllerFactory); 151 test_factory_.reset(new TestChromeWebUIControllerFactory);
131 content::WebUIControllerFactory::RegisterFactory(test_factory_.get()); 152 content::WebUIControllerFactory::RegisterFactory(test_factory_.get());
132 test_factory_->AddFactoryOverride( 153 test_factory_->AddFactoryOverride(
133 GURL(kFooWebUIURL).host(), &foo_provider_); 154 GURL(kFooWebUIURL).host(), &foo_provider_);
134 } 155 }
135 156
(...skipping 17 matching lines...) Expand all
153 ui_test_utils::NavigateToURL(browser(), GURL(kFooWebUIURL)); 174 ui_test_utils::NavigateToURL(browser(), GURL(kFooWebUIURL));
154 } 175 }
155 176
156 // Make sure that the foo webui handler does not get created when we try to 177 // Make sure that the foo webui handler does not get created when we try to
157 // load it inside the iframe of the login ui. 178 // load it inside the iframe of the login ui.
158 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, NoWebUIInIframe) { 179 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest, NoWebUIInIframe) {
159 GURL url = signin::GetPromoURL(signin::SOURCE_START_PAGE, false). 180 GURL url = signin::GetPromoURL(signin::SOURCE_START_PAGE, false).
160 Resolve("?source=0&frameUrl=chrome://foo"); 181 Resolve("?source=0&frameUrl=chrome://foo");
161 EXPECT_CALL(foo_provider(), NewWebUI(_, _)).Times(0); 182 EXPECT_CALL(foo_provider(), NewWebUI(_, _)).Times(0);
162 ui_test_utils::NavigateToURL(browser(), url); 183 ui_test_utils::NavigateToURL(browser(), url);
184 WaitUntilUIReady();
163 } 185 }
186
187 // Make sure that the gaia iframe cannot trigger top-frame navigation.
188 IN_PROC_BROWSER_TEST_F(InlineLoginUISafeIframeBrowserTest,
189 TopFrameNavigationDisallowed) {
190 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
191 // Loads into gaia iframe a web page that attempts to deframe on load.
192 GURL deframe_url(embedded_test_server()->GetURL("/login/deframe.html"));
193 GURL url(net::AppendOrReplaceQueryParameter(
194 signin::GetPromoURL(signin::SOURCE_START_PAGE, false),
195 "frameUrl", deframe_url.spec()));
196 ui_test_utils::NavigateToURL(browser(), url);
197 WaitUntilUIReady();
198
199 content::WebContents* contents =
200 browser()->tab_strip_model()->GetActiveWebContents();
201 EXPECT_EQ(url, contents->GetVisibleURL());
202
203 content::NavigationController& controller = contents->GetController();
204 EXPECT_TRUE(controller.GetPendingEntry() == NULL);
205 }
OLDNEW
« no previous file with comments | « chrome/browser/resources/inline_login/inline_login.js ('k') | chrome/test/data/login/deframe.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698