| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 } | 94 } |
| 95 }; | 95 }; |
| 96 | 96 |
| 97 // Flaky http://crbug.com/238674 | 97 // Flaky http://crbug.com/238674 |
| 98 #if defined(OS_WIN) | 98 #if defined(OS_WIN) |
| 99 #define MAYBE_IsInstalled DISABLED_IsInstalled | 99 #define MAYBE_IsInstalled DISABLED_IsInstalled |
| 100 #else | 100 #else |
| 101 #define MAYBE_IsInstalled IsInstalled | 101 #define MAYBE_IsInstalled IsInstalled |
| 102 #endif | 102 #endif |
| 103 IN_PROC_BROWSER_TEST_F(ChromeAppAPITest, MAYBE_IsInstalled) { | 103 IN_PROC_BROWSER_TEST_F(ChromeAppAPITest, MAYBE_IsInstalled) { |
| 104 std::string app_host("app.com"); | 104 static const char kAppHost[] = "app.com"; |
| 105 std::string nonapp_host("nonapp.com"); | 105 static const char kNonAppHost[] = "nonapp.com"; |
| 106 | 106 |
| 107 host_resolver()->AddRule(app_host, "127.0.0.1"); | 107 host_resolver()->AddRule(kAppHost, "127.0.0.1"); |
| 108 host_resolver()->AddRule(nonapp_host, "127.0.0.1"); | 108 host_resolver()->AddRule(kNonAppHost, "127.0.0.1"); |
| 109 ASSERT_TRUE(test_server()->Start()); | 109 ASSERT_TRUE(test_server()->Start()); |
| 110 | 110 |
| 111 GURL test_file_url(test_server()->GetURL("extensions/test_file.html")); | 111 GURL test_file_url(test_server()->GetURL("extensions/test_file.html")); |
| 112 GURL::Replacements replace_host; | 112 GURL::Replacements replace_host; |
| 113 | 113 |
| 114 replace_host.SetHostStr(app_host); | 114 replace_host.SetHostStr(kAppHost); |
| 115 GURL app_url(test_file_url.ReplaceComponents(replace_host)); | 115 GURL app_url(test_file_url.ReplaceComponents(replace_host)); |
| 116 | 116 |
| 117 replace_host.SetHostStr(nonapp_host); | 117 replace_host.SetHostStr(kNonAppHost); |
| 118 GURL non_app_url(test_file_url.ReplaceComponents(replace_host)); | 118 GURL non_app_url(test_file_url.ReplaceComponents(replace_host)); |
| 119 | 119 |
| 120 // Before the app is installed, app.com does not think that it is installed | 120 // Before the app is installed, app.com does not think that it is installed |
| 121 ui_test_utils::NavigateToURL(browser(), app_url); | 121 ui_test_utils::NavigateToURL(browser(), app_url); |
| 122 EXPECT_FALSE(IsAppInstalledInMainFrame()); | 122 EXPECT_FALSE(IsAppInstalledInMainFrame()); |
| 123 | 123 |
| 124 // Load an app which includes app.com in its extent. | 124 // Load an app which includes app.com in its extent. |
| 125 const Extension* extension = LoadExtension( | 125 const Extension* extension = LoadExtension( |
| 126 test_data_dir_.AppendASCII("app_dot_com_app")); | 126 test_data_dir_.AppendASCII("app_dot_com_app")); |
| 127 ASSERT_TRUE(extension); | 127 ASSERT_TRUE(extension); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 " }" | 181 " }" |
| 182 " }()" | 182 " }()" |
| 183 ");", | 183 ");", |
| 184 &result)); | 184 &result)); |
| 185 | 185 |
| 186 // Should not be able to alter window.chrome.app.isInstalled from javascript"; | 186 // Should not be able to alter window.chrome.app.isInstalled from javascript"; |
| 187 EXPECT_EQ("true", result); | 187 EXPECT_EQ("true", result); |
| 188 } | 188 } |
| 189 | 189 |
| 190 IN_PROC_BROWSER_TEST_F(ChromeAppAPITest, GetDetailsForFrame) { | 190 IN_PROC_BROWSER_TEST_F(ChromeAppAPITest, GetDetailsForFrame) { |
| 191 std::string app_host("app.com"); | 191 const char kAppHost[] = "app.com"; |
| 192 std::string nonapp_host("nonapp.com"); | 192 const char kNonAppHost[] = "nonapp.com"; |
| 193 std::string checkout_host("checkout.com"); | 193 const char kCheckoutHost[] = "checkout.com"; |
| 194 | 194 |
| 195 host_resolver()->AddRule(app_host, "127.0.0.1"); | 195 host_resolver()->AddRule(kAppHost, "127.0.0.1"); |
| 196 host_resolver()->AddRule(nonapp_host, "127.0.0.1"); | 196 host_resolver()->AddRule(kNonAppHost, "127.0.0.1"); |
| 197 host_resolver()->AddRule(checkout_host, "127.0.0.1"); | 197 host_resolver()->AddRule(kCheckoutHost, "127.0.0.1"); |
| 198 ASSERT_TRUE(test_server()->Start()); | 198 ASSERT_TRUE(test_server()->Start()); |
| 199 | 199 |
| 200 GURL test_file_url(test_server()->GetURL( | 200 GURL test_file_url(test_server()->GetURL( |
| 201 "files/extensions/get_app_details_for_frame.html")); | 201 "files/extensions/get_app_details_for_frame.html")); |
| 202 GURL::Replacements replace_host; | 202 GURL::Replacements replace_host; |
| 203 | 203 |
| 204 replace_host.SetHostStr(checkout_host); | 204 replace_host.SetHostStr(kCheckoutHost); |
| 205 GURL checkout_url(test_file_url.ReplaceComponents(replace_host)); | 205 GURL checkout_url(test_file_url.ReplaceComponents(replace_host)); |
| 206 | 206 |
| 207 replace_host.SetHostStr(app_host); | 207 replace_host.SetHostStr(kAppHost); |
| 208 GURL app_url(test_file_url.ReplaceComponents(replace_host)); | 208 GURL app_url(test_file_url.ReplaceComponents(replace_host)); |
| 209 | 209 |
| 210 // Load an app which includes app.com in its extent. | 210 // Load an app which includes app.com in its extent. |
| 211 const Extension* extension = LoadExtension( | 211 const Extension* extension = LoadExtension( |
| 212 test_data_dir_.AppendASCII("app_dot_com_app")); | 212 test_data_dir_.AppendASCII("app_dot_com_app")); |
| 213 ASSERT_TRUE(extension); | 213 ASSERT_TRUE(extension); |
| 214 | 214 |
| 215 // Test that normal pages (even apps) cannot use getDetailsForFrame(). | 215 // Test that normal pages (even apps) cannot use getDetailsForFrame(). |
| 216 ui_test_utils::NavigateToURL(browser(), app_url); | 216 ui_test_utils::NavigateToURL(browser(), app_url); |
| 217 const char kTestUnsuccessfulAccess[] = | 217 const char kTestUnsuccessfulAccess[] = |
| (...skipping 22 matching lines...) Expand all Loading... |
| 240 scoped_ptr<base::DictionaryValue> app_details( | 240 scoped_ptr<base::DictionaryValue> app_details( |
| 241 static_cast<base::DictionaryValue*>(base::JSONReader::Read(json))); | 241 static_cast<base::DictionaryValue*>(base::JSONReader::Read(json))); |
| 242 // extension->manifest() does not contain the id. | 242 // extension->manifest() does not contain the id. |
| 243 app_details->Remove("id", NULL); | 243 app_details->Remove("id", NULL); |
| 244 EXPECT_TRUE(app_details.get()); | 244 EXPECT_TRUE(app_details.get()); |
| 245 EXPECT_TRUE(app_details->Equals(extension->manifest()->value())); | 245 EXPECT_TRUE(app_details->Equals(extension->manifest()->value())); |
| 246 } | 246 } |
| 247 | 247 |
| 248 | 248 |
| 249 IN_PROC_BROWSER_TEST_F(ChromeAppAPITest, InstallAndRunningState) { | 249 IN_PROC_BROWSER_TEST_F(ChromeAppAPITest, InstallAndRunningState) { |
| 250 std::string app_host("app.com"); | 250 static const char kAppHost[] = "app.com"; |
| 251 std::string non_app_host("nonapp.com"); | 251 static const char kNonAppHost[] = "nonapp.com"; |
| 252 | 252 |
| 253 host_resolver()->AddRule(app_host, "127.0.0.1"); | 253 host_resolver()->AddRule(kAppHost, "127.0.0.1"); |
| 254 host_resolver()->AddRule(non_app_host, "127.0.0.1"); | 254 host_resolver()->AddRule(kNonAppHost, "127.0.0.1"); |
| 255 ASSERT_TRUE(test_server()->Start()); | 255 ASSERT_TRUE(test_server()->Start()); |
| 256 | 256 |
| 257 GURL test_file_url(test_server()->GetURL( | 257 GURL test_file_url(test_server()->GetURL( |
| 258 "files/extensions/get_app_details_for_frame.html")); | 258 "files/extensions/get_app_details_for_frame.html")); |
| 259 GURL::Replacements replace_host; | 259 GURL::Replacements replace_host; |
| 260 | 260 |
| 261 replace_host.SetHostStr(app_host); | 261 replace_host.SetHostStr(kAppHost); |
| 262 GURL app_url(test_file_url.ReplaceComponents(replace_host)); | 262 GURL app_url(test_file_url.ReplaceComponents(replace_host)); |
| 263 | 263 |
| 264 replace_host.SetHostStr(non_app_host); | 264 replace_host.SetHostStr(kNonAppHost); |
| 265 GURL non_app_url(test_file_url.ReplaceComponents(replace_host)); | 265 GURL non_app_url(test_file_url.ReplaceComponents(replace_host)); |
| 266 | 266 |
| 267 // Before the app is installed, app.com does not think that it is installed | 267 // Before the app is installed, app.com does not think that it is installed |
| 268 ui_test_utils::NavigateToURL(browser(), app_url); | 268 ui_test_utils::NavigateToURL(browser(), app_url); |
| 269 | 269 |
| 270 EXPECT_EQ("not_installed", InstallStateInMainFrame()); | 270 EXPECT_EQ("not_installed", InstallStateInMainFrame()); |
| 271 EXPECT_EQ("cannot_run", RunningStateInMainFrame()); | 271 EXPECT_EQ("cannot_run", RunningStateInMainFrame()); |
| 272 EXPECT_FALSE(IsAppInstalledInMainFrame()); | 272 EXPECT_FALSE(IsAppInstalledInMainFrame()); |
| 273 | 273 |
| 274 const Extension* extension = LoadExtension( | 274 const Extension* extension = LoadExtension( |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 EXPECT_EQ("not_installed", InstallStateInMainFrame()); | 307 EXPECT_EQ("not_installed", InstallStateInMainFrame()); |
| 308 EXPECT_EQ("cannot_run", RunningStateInMainFrame()); | 308 EXPECT_EQ("cannot_run", RunningStateInMainFrame()); |
| 309 EXPECT_FALSE(IsAppInstalledInMainFrame()); | 309 EXPECT_FALSE(IsAppInstalledInMainFrame()); |
| 310 | 310 |
| 311 EXPECT_EQ("installed", InstallStateInIFrame()); | 311 EXPECT_EQ("installed", InstallStateInIFrame()); |
| 312 EXPECT_EQ("cannot_run", RunningStateInIFrame()); | 312 EXPECT_EQ("cannot_run", RunningStateInIFrame()); |
| 313 EXPECT_FALSE(IsAppInstalledInIFrame()); | 313 EXPECT_FALSE(IsAppInstalledInIFrame()); |
| 314 } | 314 } |
| 315 | 315 |
| 316 IN_PROC_BROWSER_TEST_F(ChromeAppAPITest, InstallAndRunningStateFrame) { | 316 IN_PROC_BROWSER_TEST_F(ChromeAppAPITest, InstallAndRunningStateFrame) { |
| 317 std::string app_host("app.com"); | 317 static const char kAppHost[] = "app.com"; |
| 318 std::string non_app_host("nonapp.com"); | 318 static const char kNonAppHost[] = "nonapp.com"; |
| 319 | 319 |
| 320 host_resolver()->AddRule(app_host, "127.0.0.1"); | 320 host_resolver()->AddRule(kAppHost, "127.0.0.1"); |
| 321 host_resolver()->AddRule(non_app_host, "127.0.0.1"); | 321 host_resolver()->AddRule(kNonAppHost, "127.0.0.1"); |
| 322 ASSERT_TRUE(test_server()->Start()); | 322 ASSERT_TRUE(test_server()->Start()); |
| 323 | 323 |
| 324 GURL test_file_url(test_server()->GetURL( | 324 GURL test_file_url(test_server()->GetURL( |
| 325 "files/extensions/get_app_details_for_frame_reversed.html")); | 325 "files/extensions/get_app_details_for_frame_reversed.html")); |
| 326 GURL::Replacements replace_host; | 326 GURL::Replacements replace_host; |
| 327 | 327 |
| 328 replace_host.SetHostStr(app_host); | 328 replace_host.SetHostStr(kAppHost); |
| 329 GURL app_url(test_file_url.ReplaceComponents(replace_host)); | 329 GURL app_url(test_file_url.ReplaceComponents(replace_host)); |
| 330 | 330 |
| 331 replace_host.SetHostStr(non_app_host); | 331 replace_host.SetHostStr(kNonAppHost); |
| 332 GURL non_app_url(test_file_url.ReplaceComponents(replace_host)); | 332 GURL non_app_url(test_file_url.ReplaceComponents(replace_host)); |
| 333 | 333 |
| 334 // Check the install and running state of a non-app iframe running | 334 // Check the install and running state of a non-app iframe running |
| 335 // within an app. | 335 // within an app. |
| 336 ui_test_utils::NavigateToURL(browser(), app_url); | 336 ui_test_utils::NavigateToURL(browser(), app_url); |
| 337 | 337 |
| 338 EXPECT_EQ("not_installed", InstallStateInIFrame()); | 338 EXPECT_EQ("not_installed", InstallStateInIFrame()); |
| 339 EXPECT_EQ("cannot_run", RunningStateInIFrame()); | 339 EXPECT_EQ("cannot_run", RunningStateInIFrame()); |
| 340 EXPECT_FALSE(IsAppInstalledInIFrame()); | 340 EXPECT_FALSE(IsAppInstalledInIFrame()); |
| 341 } | 341 } |
| OLD | NEW |