OLD | NEW |
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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 99 CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
100 | 100 |
101 // Go back twice. | 101 // Go back twice. |
102 // If bug fixed, we cannot go back anymore. | 102 // If bug fixed, we cannot go back anymore. |
103 // If not fixed, we will redirect back to app2 and can go back again. | 103 // If not fixed, we will redirect back to app2 and can go back again. |
104 chrome::GoBack(browser(), CURRENT_TAB); | 104 chrome::GoBack(browser(), CURRENT_TAB); |
105 chrome::GoBack(browser(), CURRENT_TAB); | 105 chrome::GoBack(browser(), CURRENT_TAB); |
106 EXPECT_FALSE(chrome::CanGoBack(browser())); | 106 EXPECT_FALSE(chrome::CanGoBack(browser())); |
107 } | 107 } |
108 | 108 |
| 109 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, CrossSiteDataPost) { |
| 110 host_resolver()->AddRule("*", "127.0.0.1"); |
| 111 ASSERT_TRUE(test_server()->Start()); |
| 112 |
| 113 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("isolated_apps/app1"))); |
| 114 |
| 115 GURL base_url = test_server()->GetURL("files/extensions/isolated_apps/"); |
| 116 GURL::Replacements replace_host; |
| 117 std::string host_str("localhost"); // Must stay in scope with replace_host. |
| 118 replace_host.SetHostStr(host_str); |
| 119 base_url = base_url.ReplaceComponents(replace_host); |
| 120 std::string resolve_url ="app1/main.html"; |
| 121 ui_test_utils::NavigateToURLWithDisposition( |
| 122 browser(), base_url.Resolve(resolve_url), |
| 123 CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 124 |
| 125 WebContents* tab0 = chrome::GetWebContentsAt(browser(), 0); |
| 126 base::ProcessHandle old_process = tab0->GetRenderProcessHost()->GetHandle(); |
| 127 |
| 128 std::string data = "post \0\ndata"; |
| 129 GURL echo_url = test_server()->GetURL("echoall"); |
| 130 std::string jsSubmit = "(function submitform() {"; |
| 131 jsSubmit.append("var form = document.createElement(\"form\");"); |
| 132 jsSubmit.append("form.setAttribute(\"method\", \"POST\");"); |
| 133 jsSubmit.append("form.setAttribute(\"action\", \""); |
| 134 jsSubmit.append(echo_url.spec().c_str()); |
| 135 jsSubmit.append("\");var hiddenField = document.createElement(\"input\");"); |
| 136 jsSubmit.append("hiddenField.setAttribute(\"type\", \"hidden\");"); |
| 137 jsSubmit.append("hiddenField.setAttribute(\"name\", \"data\");"); |
| 138 jsSubmit.append("hiddenField.setAttribute(\"value\", \"" + data + "\");"); |
| 139 jsSubmit.append("form.appendChild(hiddenField);"); |
| 140 jsSubmit.append("document.body.appendChild(form);"); |
| 141 jsSubmit.append("form.submit();"); |
| 142 jsSubmit.append("})()"); |
| 143 |
| 144 content::WindowedNotificationObserver tab_loaded_observer( |
| 145 content::NOTIFICATION_LOAD_STOP, |
| 146 content::Source<NavigationController>(&tab0->GetController())); |
| 147 ASSERT_TRUE(ExecuteJavaScript( |
| 148 chrome::GetWebContentsAt(browser(), 0)->GetRenderViewHost(), |
| 149 L"", |
| 150 ASCIIToWide(jsSubmit))); |
| 151 tab_loaded_observer.Wait(); |
| 152 |
| 153 // Make sure we are in the new process. |
| 154 WebContents* tab1 = chrome::GetWebContentsAt(browser(), 0); |
| 155 EXPECT_NE(old_process, |
| 156 tab1->GetRenderProcessHost()->GetHandle()); |
| 157 |
| 158 // The response page from TestServer displayed the POST data |
| 159 // within the <pre> tag. We inject script to extract the POST data |
| 160 // from this page and compare with the POST data we submitted. |
| 161 std::string getResult = "window.domAutomationController.send("; |
| 162 getResult.append("document.getElementsByTagName('pre')[0].firstChild.data);"); |
| 163 std::string value; |
| 164 ASSERT_TRUE(ExecuteJavaScriptAndExtractString( |
| 165 chrome::GetWebContentsAt(browser(), 0)->GetRenderViewHost(), |
| 166 L"", |
| 167 ASCIIToWide(getResult), |
| 168 &value)); |
| 169 EXPECT_EQ("data=" + data + "\n", value); |
| 170 } |
| 171 |
| 172 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, CrossSiteFilePost) { |
| 173 } |
| 174 |
109 // Tests that cookies set within an isolated app are not visible to normal | 175 // Tests that cookies set within an isolated app are not visible to normal |
110 // pages or other apps. | 176 // pages or other apps. |
111 // | 177 // |
112 // TODO(ajwong): Also test what happens if an app spans multiple sites in its | 178 // TODO(ajwong): Also test what happens if an app spans multiple sites in its |
113 // extent. These origins should also be isolated, but still have origin-based | 179 // extent. These origins should also be isolated, but still have origin-based |
114 // separation as you would expect. | 180 // separation as you would expect. |
115 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, CookieIsolation) { | 181 IN_PROC_BROWSER_TEST_F(IsolatedAppTest, CookieIsolation) { |
116 host_resolver()->AddRule("*", "127.0.0.1"); | 182 host_resolver()->AddRule("*", "127.0.0.1"); |
117 ASSERT_TRUE(test_server()->Start()); | 183 ASSERT_TRUE(test_server()->Start()); |
118 | 184 |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 EXPECT_EQ("ss_app2", result); | 533 EXPECT_EQ("ss_app2", result); |
468 | 534 |
469 ui_test_utils::NavigateToURLWithDisposition( | 535 ui_test_utils::NavigateToURLWithDisposition( |
470 browser(), base_url.Resolve("non_app/main.html"), | 536 browser(), base_url.Resolve("non_app/main.html"), |
471 CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 537 CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
472 ASSERT_TRUE(ExecuteJavaScriptAndExtractString( | 538 ASSERT_TRUE(ExecuteJavaScriptAndExtractString( |
473 chrome::GetWebContentsAt(browser(), 0)->GetRenderViewHost(), | 539 chrome::GetWebContentsAt(browser(), 0)->GetRenderViewHost(), |
474 L"", kRetrieveSessionStorage.c_str(), &result)); | 540 L"", kRetrieveSessionStorage.c_str(), &result)); |
475 EXPECT_EQ("ss_normal", result); | 541 EXPECT_EQ("ss_normal", result); |
476 } | 542 } |
OLD | NEW |