|
5 | 5 | #include "base/command_line.h"
|
6 | 6 | #include "base/stringprintf.h"
|
7 | 7 | #include "base/utf_string_conversions.h"
|
| 8 | +#include "chrome/browser/automation/automation_util.h" |
8 | 9 | #include "chrome/browser/extensions/extension_apitest.h"
|
9 | 10 | #include "chrome/browser/extensions/extension_browsertest.h"
|
10 | 11 | #include "chrome/browser/extensions/extension_host.h"
|
@@ -179,3 +180,34 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Restrictions) {
|
179 | 180 | IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApi) {
|
180 | 181 | ASSERT_TRUE(RunPlatformAppTest("platform_apps/windows_api")) << message_;
|
181 | 182 | }
|
| 183 | + |
| 184 | +// Tests that platform apps have isolated storage by default. |
| 185 | +IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Isolation) { |
| 186 | + ASSERT_TRUE(StartTestServer()); |
| 187 | + |
| 188 | + // Load a (non-app) page under the "localhost" origin that sets a cookie. |
| 189 | + GURL set_cookie_url = test_server()->GetURL( |
| 190 | + "files/extensions/platform_apps/isolation/set_cookie.html"); |
| 191 | + GURL::Replacements replace_host; |
| 192 | + std::string host_str("localhost"); // Must stay in scope with replace_host. |
| 193 | + replace_host.SetHostStr(host_str); |
| 194 | + set_cookie_url = set_cookie_url.ReplaceComponents(replace_host); |
| 195 | + |
| 196 | + ui_test_utils::NavigateToURLWithDisposition( |
| 197 | + browser(), set_cookie_url, |
| 198 | + CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 199 | + |
| 200 | + // Make sure the cookie is set. |
| 201 | + int cookie_size; |
| 202 | + std::string cookie_value; |
| 203 | + automation_util::GetCookies( |
| 204 | + set_cookie_url, |
| 205 | + browser()->GetWebContentsAt(0), |
| 206 | + &cookie_size, |
| 207 | + &cookie_value); |
| 208 | + ASSERT_EQ("testCookie=1", cookie_value); |
| 209 | + |
| 210 | + // Let the platform app request the same URL, and make sure that it doesn't |
| 211 | + // see the cookie. |
| 212 | + ASSERT_TRUE(RunPlatformAppTest("platform_apps/isolation")) << message_; |
| 213 | +} |
0 commit comments