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

Side by Side Diff: chrome/browser/extensions/isolated_app_browsertest.cc

Issue 11193051: To fix the cross-site post submission bug. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: New OpenURL function and DataType Test Created 8 years, 1 month 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/utf_string_conversions.h" 5 #include "base/utf_string_conversions.h"
6 #include "chrome/browser/automation/automation_util.h" 6 #include "chrome/browser/automation/automation_util.h"
7 #include "chrome/browser/extensions/extension_apitest.h" 7 #include "chrome/browser/extensions/extension_apitest.h"
8 #include "chrome/browser/extensions/extension_host.h" 8 #include "chrome/browser/extensions/extension_host.h"
9 #include "chrome/browser/extensions/extension_service.h" 9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 68
69 private: 69 private:
70 virtual void SetUpCommandLine(CommandLine* command_line) { 70 virtual void SetUpCommandLine(CommandLine* command_line) {
71 ExtensionBrowserTest::SetUpCommandLine(command_line); 71 ExtensionBrowserTest::SetUpCommandLine(command_line);
72 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); 72 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
73 } 73 }
74 }; 74 };
75 75
76 } // namespace 76 } // namespace
77 77
78 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, CrossSiteDataPost) {
irobert 2012/11/09 19:07:57 This Test is for the DataType Post Submission. I a
79 host_resolver()->AddRule("*", "127.0.0.1");
80 ASSERT_TRUE(test_server()->Start());
81
82 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1")));
83
84 GURL base_url = test_server()->GetURL("files/extensions/isolated_apps/");
85 GURL::Replacements replace_host;
86 std::string host_str("localhost"); // Must stay in scope with replace_host.
87 replace_host.SetHostStr(host_str);
88 base_url = base_url.ReplaceComponents(replace_host);
89 std::string resolve_url ="app1/main.html";
90 ui_test_utils::NavigateToURLWithDisposition(
91 browser(), base_url.Resolve(resolve_url),
92 CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
93
94 WebContents* tab0 = chrome::GetWebContentsAt(browser(), 0);
95 pid_t old_process = tab0->GetRenderProcessHost()->GetHandle();
96
97 std::string data = "post \0\ndata";
98 GURL echo_url = test_server()->GetURL("echoall");
99 std::string jsSubmit = "(function submitform() {";
100 jsSubmit.append("var form = document.createElement(\"form\");");
101 jsSubmit.append("form.setAttribute(\"method\", \"POST\");");
102 jsSubmit.append("form.setAttribute(\"action\", \"");
103 jsSubmit.append(echo_url.spec().c_str());
104 jsSubmit.append("\");var hiddenField = document.createElement(\"input\");");
105 jsSubmit.append("hiddenField.setAttribute(\"type\", \"hidden\");");
106 jsSubmit.append("hiddenField.setAttribute(\"name\", \"data\");");
107 jsSubmit.append("hiddenField.setAttribute(\"value\", \"" + data + "\");");
108 jsSubmit.append("form.appendChild(hiddenField);");
109 jsSubmit.append("document.body.appendChild(form);");
110 jsSubmit.append("form.submit();");
111 jsSubmit.append("})()");
112
113 ASSERT_TRUE(ExecuteJavaScript(
114 chrome::GetWebContentsAt(browser(), 0)->GetRenderViewHost(),
115 L"",
116 ASCIIToWide(jsSubmit)));
117
118 const string16 expected_title = ASCIIToUTF16("echoall");
119 content::TitleWatcher title_watcher(tab0, expected_title);
120 string16 actual_title = title_watcher.WaitAndGetTitle();
121 EXPECT_EQ(expected_title, actual_title);
122
123 // Make Sure we are in the new process
124 WebContents* tab1 = chrome::GetWebContentsAt(browser(), 0);
125 EXPECT_NE(old_process,
126 tab1->GetRenderProcessHost()->GetHandle());
127
128 std::string getResult = "window.domAutomationController.send(";
129 getResult.append("document.getElementsByTagName('pre')[0].firstChild.data);");
130 std::string value;
131 ASSERT_TRUE(ExecuteJavaScriptAndExtractString(
132 chrome::GetWebContentsAt(browser(), 0)->GetRenderViewHost(),
133 L"",
134 ASCIIToWide(getResult),
135 &value));
136 EXPECT_EQ("data="+data+"\n", value);
137 }
138
78 // Tests that cookies set within an isolated app are not visible to normal 139 // Tests that cookies set within an isolated app are not visible to normal
79 // pages or other apps. 140 // pages or other apps.
80 // 141 //
81 // TODO(ajwong): Also test what happens if an app spans multiple sites in its 142 // TODO(ajwong): Also test what happens if an app spans multiple sites in its
82 // extent. These origins should also be isolated, but still have origin-based 143 // extent. These origins should also be isolated, but still have origin-based
83 // separation as you would expect. 144 // separation as you would expect.
84 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, CookieIsolation) { 145 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, CookieIsolation) {
85 host_resolver()->AddRule("*", "127.0.0.1"); 146 host_resolver()->AddRule("*", "127.0.0.1");
86 ASSERT_TRUE(test_server()->Start()); 147 ASSERT_TRUE(test_server()->Start());
87 148
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 EXPECT_EQ("ss_app2", result); 492 EXPECT_EQ("ss_app2", result);
432 493
433 ui_test_utils::NavigateToURLWithDisposition( 494 ui_test_utils::NavigateToURLWithDisposition(
434 browser(), base_url.Resolve("non_app/main.html"), 495 browser(), base_url.Resolve("non_app/main.html"),
435 CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 496 CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
436 ASSERT_TRUE(ExecuteJavaScriptAndExtractString( 497 ASSERT_TRUE(ExecuteJavaScriptAndExtractString(
437 chrome::GetWebContentsAt(browser(), 0)->GetRenderViewHost(), 498 chrome::GetWebContentsAt(browser(), 0)->GetRenderViewHost(),
438 L"", kRetrieveSessionStorage.c_str(), &result)); 499 L"", kRetrieveSessionStorage.c_str(), &result));
439 EXPECT_EQ("ss_normal", result); 500 EXPECT_EQ("ss_normal", result);
440 } 501 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/browser.cc » ('j') | content/browser/web_contents/navigation_entry_impl.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698