| 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 <memory> | 5 #include <memory> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/extensions/extension_browsertest.h" | 12 #include "chrome/browser/extensions/extension_browsertest.h" |
| 13 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 17 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
| 18 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 19 #include "content/public/test/browser_test_utils.h" | 19 #include "content/public/test/browser_test_utils.h" |
| 20 #include "extensions/common/extension.h" | 20 #include "extensions/common/extension.h" |
| 21 #include "extensions/common/manifest.h" | 21 #include "extensions/common/manifest.h" |
| 22 #include "net/dns/mock_host_resolver.h" | 22 #include "net/dns/mock_host_resolver.h" |
| 23 #include "net/test/embedded_test_server/embedded_test_server.h" | 23 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 24 #include "url/gurl.h" | 24 #include "url/gurl.h" |
| 25 | 25 |
| 26 using extensions::Extension; | 26 using extensions::Extension; |
| 27 | 27 |
| 28 class ChromeAppAPITest : public ExtensionBrowserTest { | 28 class ChromeAppAPITest : public ExtensionBrowserTest { |
| 29 void SetUpOnMainThread() override { |
| 30 ExtensionBrowserTest::SetUpOnMainThread(); |
| 31 host_resolver()->AddRule("*", "127.0.0.1"); |
| 32 ASSERT_TRUE(embedded_test_server()->Start()); |
| 33 } |
| 34 |
| 29 protected: | 35 protected: |
| 30 bool IsAppInstalledInMainFrame() { | 36 bool IsAppInstalledInMainFrame() { |
| 31 return IsAppInstalledInFrame( | 37 return IsAppInstalledInFrame( |
| 32 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame()); | 38 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame()); |
| 33 } | 39 } |
| 34 bool IsAppInstalledInIFrame() { | 40 bool IsAppInstalledInIFrame() { |
| 35 return IsAppInstalledInFrame(GetIFrame()); | 41 return IsAppInstalledInFrame(GetIFrame()); |
| 36 } | 42 } |
| 37 bool IsAppInstalledInFrame(content::RenderFrameHost* frame) { | 43 bool IsAppInstalledInFrame(content::RenderFrameHost* frame) { |
| 38 const char kGetAppIsInstalled[] = | 44 const char kGetAppIsInstalled[] = |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 | 88 |
| 83 private: | 89 private: |
| 84 content::RenderFrameHost* GetIFrame() { | 90 content::RenderFrameHost* GetIFrame() { |
| 85 return content::FrameMatchingPredicate( | 91 return content::FrameMatchingPredicate( |
| 86 browser()->tab_strip_model()->GetActiveWebContents(), | 92 browser()->tab_strip_model()->GetActiveWebContents(), |
| 87 base::Bind(&content::FrameIsChildOfMainFrame)); | 93 base::Bind(&content::FrameIsChildOfMainFrame)); |
| 88 } | 94 } |
| 89 }; | 95 }; |
| 90 | 96 |
| 91 IN_PROC_BROWSER_TEST_F(ChromeAppAPITest, IsInstalled) { | 97 IN_PROC_BROWSER_TEST_F(ChromeAppAPITest, IsInstalled) { |
| 92 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 93 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 94 GURL app_url = | 98 GURL app_url = |
| 95 embedded_test_server()->GetURL("app.com", "/extensions/test_file.html"); | 99 embedded_test_server()->GetURL("app.com", "/extensions/test_file.html"); |
| 96 GURL non_app_url = embedded_test_server()->GetURL( | 100 GURL non_app_url = embedded_test_server()->GetURL( |
| 97 "nonapp.com", "/extensions/test_file.html"); | 101 "nonapp.com", "/extensions/test_file.html"); |
| 98 | 102 |
| 99 // Before the app is installed, app.com does not think that it is installed | 103 // Before the app is installed, app.com does not think that it is installed |
| 100 ui_test_utils::NavigateToURL(browser(), app_url); | 104 ui_test_utils::NavigateToURL(browser(), app_url); |
| 101 EXPECT_FALSE(IsAppInstalledInMainFrame()); | 105 EXPECT_FALSE(IsAppInstalledInMainFrame()); |
| 102 | 106 |
| 103 // Load an app which includes app.com in its extent. | 107 // Load an app which includes app.com in its extent. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 " }" | 165 " }" |
| 162 " }()" | 166 " }()" |
| 163 ");", | 167 ");", |
| 164 &result)); | 168 &result)); |
| 165 | 169 |
| 166 // Should not be able to alter window.chrome.app.isInstalled from javascript"; | 170 // Should not be able to alter window.chrome.app.isInstalled from javascript"; |
| 167 EXPECT_EQ("true", result); | 171 EXPECT_EQ("true", result); |
| 168 } | 172 } |
| 169 | 173 |
| 170 IN_PROC_BROWSER_TEST_F(ChromeAppAPITest, InstallAndRunningState) { | 174 IN_PROC_BROWSER_TEST_F(ChromeAppAPITest, InstallAndRunningState) { |
| 171 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 172 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 173 GURL app_url = embedded_test_server()->GetURL( | 175 GURL app_url = embedded_test_server()->GetURL( |
| 174 "app.com", "/extensions/get_app_details_for_frame.html"); | 176 "app.com", "/extensions/get_app_details_for_frame.html"); |
| 175 GURL non_app_url = embedded_test_server()->GetURL( | 177 GURL non_app_url = embedded_test_server()->GetURL( |
| 176 "nonapp.com", "/extensions/get_app_details_for_frame.html"); | 178 "nonapp.com", "/extensions/get_app_details_for_frame.html"); |
| 177 | 179 |
| 178 // Before the app is installed, app.com does not think that it is installed | 180 // Before the app is installed, app.com does not think that it is installed |
| 179 ui_test_utils::NavigateToURL(browser(), app_url); | 181 ui_test_utils::NavigateToURL(browser(), app_url); |
| 180 | 182 |
| 181 EXPECT_EQ("not_installed", InstallStateInMainFrame()); | 183 EXPECT_EQ("not_installed", InstallStateInMainFrame()); |
| 182 EXPECT_EQ("cannot_run", RunningStateInMainFrame()); | 184 EXPECT_EQ("cannot_run", RunningStateInMainFrame()); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 EXPECT_EQ("not_installed", InstallStateInMainFrame()); | 220 EXPECT_EQ("not_installed", InstallStateInMainFrame()); |
| 219 EXPECT_EQ("cannot_run", RunningStateInMainFrame()); | 221 EXPECT_EQ("cannot_run", RunningStateInMainFrame()); |
| 220 EXPECT_FALSE(IsAppInstalledInMainFrame()); | 222 EXPECT_FALSE(IsAppInstalledInMainFrame()); |
| 221 | 223 |
| 222 EXPECT_EQ("installed", InstallStateInIFrame()); | 224 EXPECT_EQ("installed", InstallStateInIFrame()); |
| 223 EXPECT_EQ("cannot_run", RunningStateInIFrame()); | 225 EXPECT_EQ("cannot_run", RunningStateInIFrame()); |
| 224 EXPECT_FALSE(IsAppInstalledInIFrame()); | 226 EXPECT_FALSE(IsAppInstalledInIFrame()); |
| 225 } | 227 } |
| 226 | 228 |
| 227 IN_PROC_BROWSER_TEST_F(ChromeAppAPITest, InstallAndRunningStateFrame) { | 229 IN_PROC_BROWSER_TEST_F(ChromeAppAPITest, InstallAndRunningStateFrame) { |
| 228 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 229 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 230 GURL app_url = embedded_test_server()->GetURL( | 230 GURL app_url = embedded_test_server()->GetURL( |
| 231 "app.com", "/extensions/get_app_details_for_frame_reversed.html"); | 231 "app.com", "/extensions/get_app_details_for_frame_reversed.html"); |
| 232 | 232 |
| 233 // Check the install and running state of a non-app iframe running | 233 // Check the install and running state of a non-app iframe running |
| 234 // within an app. | 234 // within an app. |
| 235 ui_test_utils::NavigateToURL(browser(), app_url); | 235 ui_test_utils::NavigateToURL(browser(), app_url); |
| 236 | 236 |
| 237 EXPECT_EQ("not_installed", InstallStateInIFrame()); | 237 EXPECT_EQ("not_installed", InstallStateInIFrame()); |
| 238 EXPECT_EQ("cannot_run", RunningStateInIFrame()); | 238 EXPECT_EQ("cannot_run", RunningStateInIFrame()); |
| 239 EXPECT_FALSE(IsAppInstalledInIFrame()); | 239 EXPECT_FALSE(IsAppInstalledInIFrame()); |
| 240 } | 240 } |
| OLD | NEW |