| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
| 12 #include "chrome/test/ui_test_utils.h" | 13 #include "chrome/test/ui_test_utils.h" |
| 13 #include "content/browser/renderer_host/browser_render_process_host.h" | 14 #include "content/browser/renderer_host/browser_render_process_host.h" |
| 14 #include "content/browser/renderer_host/render_view_host.h" | 15 #include "content/browser/renderer_host/render_view_host.h" |
| 15 #include "content/browser/tab_contents/tab_contents.h" | 16 #include "content/browser/tab_contents/tab_contents.h" |
| 16 #include "net/base/mock_host_resolver.h" | 17 #include "net/base/mock_host_resolver.h" |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 class IsolatedAppApiTest : public ExtensionApiTest { | 21 class IsolatedAppApiTest : public ExtensionApiTest { |
| 21 public: | 22 public: |
| 22 // Returns whether the given tab's current URL has the given cookie. | 23 // Returns whether the given tab's current URL has the given cookie. |
| 23 bool WARN_UNUSED_RESULT HasCookie(TabContents* contents, std::string cookie) { | 24 bool WARN_UNUSED_RESULT HasCookie(TabContents* contents, std::string cookie) { |
| 24 int value_size; | 25 int value_size; |
| 25 std::string actual_cookie; | 26 std::string actual_cookie; |
| 26 automation_util::GetCookies(contents->GetURL(), contents, &value_size, | 27 automation_util::GetCookies(contents->GetURL(), contents, &value_size, |
| 27 &actual_cookie); | 28 &actual_cookie); |
| 28 return actual_cookie.find(cookie) != std::string::npos; | 29 return actual_cookie.find(cookie) != std::string::npos; |
| 29 } | 30 } |
| 30 | 31 |
| 31 const Extension* GetInstalledApp(TabContents* contents) { | 32 const Extension* GetInstalledApp(TabContents* contents) { |
| 32 return static_cast<BrowserRenderProcessHost*>( | 33 const Extension* installed_app = NULL; |
| 33 contents->render_view_host()->process())->installed_app(); | 34 ExtensionService* service = contents->profile()->GetExtensionService(); |
| 35 if (service) { |
| 36 installed_app = service->GetInstalledAppForRenderer( |
| 37 contents->render_view_host()->process()->id(); |
| 38 } |
| 39 return installed_app; |
| 34 } | 40 } |
| 35 }; | 41 }; |
| 36 | 42 |
| 37 } // namespace | 43 } // namespace |
| 38 | 44 |
| 39 // Tests that cookies set within an isolated app are not visible to normal | 45 // Tests that cookies set within an isolated app are not visible to normal |
| 40 // pages or other apps. | 46 // pages or other apps. |
| 41 IN_PROC_BROWSER_TEST_F(IsolatedAppApiTest, CookieIsolation) { | 47 IN_PROC_BROWSER_TEST_F(IsolatedAppApiTest, CookieIsolation) { |
| 42 CommandLine::ForCurrentProcess()->AppendSwitch( | 48 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 43 switches::kDisablePopupBlocking); | 49 switches::kDisablePopupBlocking); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 ASSERT_TRUE(HasCookie(browser()->GetTabContentsAt(1), "app2=4")); | 138 ASSERT_TRUE(HasCookie(browser()->GetTabContentsAt(1), "app2=4")); |
| 133 ASSERT_TRUE(HasCookie(browser()->GetTabContentsAt(1), "normalPage=5")); | 139 ASSERT_TRUE(HasCookie(browser()->GetTabContentsAt(1), "normalPage=5")); |
| 134 ASSERT_TRUE(HasCookie(browser()->GetTabContentsAt(1), "nonAppFrame=6")); | 140 ASSERT_TRUE(HasCookie(browser()->GetTabContentsAt(1), "nonAppFrame=6")); |
| 135 ASSERT_TRUE(HasCookie(browser()->GetTabContentsAt(2), "app1=3")); | 141 ASSERT_TRUE(HasCookie(browser()->GetTabContentsAt(2), "app1=3")); |
| 136 ASSERT_TRUE(HasCookie(browser()->GetTabContentsAt(2), "normalPage=5")); | 142 ASSERT_TRUE(HasCookie(browser()->GetTabContentsAt(2), "normalPage=5")); |
| 137 ASSERT_TRUE(HasCookie(browser()->GetTabContentsAt(2), "nonAppFrame=6")); | 143 ASSERT_TRUE(HasCookie(browser()->GetTabContentsAt(2), "nonAppFrame=6")); |
| 138 ASSERT_TRUE(HasCookie(browser()->GetTabContentsAt(3), "app1=3")); | 144 ASSERT_TRUE(HasCookie(browser()->GetTabContentsAt(3), "app1=3")); |
| 139 ASSERT_TRUE(HasCookie(browser()->GetTabContentsAt(3), "app2=4")); | 145 ASSERT_TRUE(HasCookie(browser()->GetTabContentsAt(3), "app2=4")); |
| 140 ASSERT_TRUE(HasCookie(browser()->GetTabContentsAt(3), "nonAppFrame=6")); | 146 ASSERT_TRUE(HasCookie(browser()->GetTabContentsAt(3), "nonAppFrame=6")); |
| 141 } | 147 } |
| OLD | NEW |