Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: chrome/browser/extensions/extension_messages_apitest.cc

Issue 114803007: Register bindings for blessed web contexts (aka hosted app contexts) by hand (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/common/extensions/api/_api_features.json » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/base64.h" 5 #include "base/base64.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 "onInstalled", 219 "onInstalled",
220 "onSuspend", 220 "onSuspend",
221 "onSuspendCanceled", 221 "onSuspendCanceled",
222 "onUpdateAvailable", 222 "onUpdateAvailable",
223 "onBrowserUpdateAvailable", 223 "onBrowserUpdateAvailable",
224 "onConnect", 224 "onConnect",
225 "onConnectExternal", 225 "onConnectExternal",
226 "onMessage", 226 "onMessage",
227 "onMessageExternal", 227 "onMessageExternal",
228 "onRestartRequired", 228 "onRestartRequired",
229 "id", 229 // Note: no "id" here because this test method is used for hosted apps,
230 // which do have access to runtime.id.
230 }; 231 };
231 232
232 // Turn the array into a JS array, which effectively gets eval()ed. 233 // Turn the array into a JS array, which effectively gets eval()ed.
233 std::string as_js_array; 234 std::string as_js_array;
234 for (size_t i = 0; i < arraysize(non_messaging_apis); ++i) { 235 for (size_t i = 0; i < arraysize(non_messaging_apis); ++i) {
235 as_js_array += as_js_array.empty() ? "[" : ","; 236 as_js_array += as_js_array.empty() ? "[" : ",";
236 as_js_array += base::StringPrintf("'%s'", non_messaging_apis[i]); 237 as_js_array += base::StringPrintf("'%s'", non_messaging_apis[i]);
237 } 238 }
238 as_js_array += "]"; 239 as_js_array += "]";
239 240
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 common_manifest())); 307 common_manifest()));
307 CHECK(extension); 308 CHECK(extension);
308 return extension; 309 return extension;
309 } 310 }
310 311
311 const Extension* LoadChromiumConnectableExtensionWithTlsChannelId() { 312 const Extension* LoadChromiumConnectableExtensionWithTlsChannelId() {
312 return LoadExtensionIntoDir(&tls_channel_id_connectable_dir_, 313 return LoadExtensionIntoDir(&tls_channel_id_connectable_dir_,
313 connectable_with_tls_channel_id_manifest()); 314 connectable_with_tls_channel_id_manifest());
314 } 315 }
315 316
317 const Extension* LoadChromiumHostedApp() {
318 const Extension* hosted_app =
319 LoadExtensionIntoDir(&hosted_app_dir_, base::StringPrintf(
320 "{"
321 " \"name\": \"chromium_hosted_app\","
322 " \"version\": \"1.0\","
323 " \"manifest_version\": 2,"
324 " \"app\": {"
325 " \"urls\": [\"%s\"],"
326 " \"launch\": {"
327 " \"web_url\": \"%s\""
328 " }\n"
329 " }\n"
330 "}", chromium_org_url().spec().c_str(),
331 chromium_org_url().spec().c_str()));
332 CHECK(hosted_app);
333 return hosted_app;
334 }
335
316 void InitializeTestServer() { 336 void InitializeTestServer() {
317 base::FilePath test_data; 337 base::FilePath test_data;
318 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data)); 338 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data));
319 embedded_test_server()->ServeFilesFromDirectory(test_data.AppendASCII( 339 embedded_test_server()->ServeFilesFromDirectory(test_data.AppendASCII(
320 "extensions/api_test/messaging/externally_connectable/sites")); 340 "extensions/api_test/messaging/externally_connectable/sites"));
321 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 341 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
322 host_resolver()->AddRule("*", embedded_test_server()->base_url().host()); 342 host_resolver()->AddRule("*", embedded_test_server()->base_url().host());
323 } 343 }
324 344
325 const char* close_background_message() { 345 const char* close_background_message() {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 CHECK(content::ExecuteScriptAndExtractString( 405 CHECK(content::ExecuteScriptAndExtractString(
386 browser()->tab_strip_model()->GetActiveWebContents(), 406 browser()->tab_strip_model()->GetActiveWebContents(),
387 base::StringPrintf("assertions.%s(%s)", method, args.c_str()), 407 base::StringPrintf("assertions.%s(%s)", method, args.c_str()),
388 &result)); 408 &result));
389 return result; 409 return result;
390 } 410 }
391 411
392 TestExtensionDir web_connectable_dir_; 412 TestExtensionDir web_connectable_dir_;
393 TestExtensionDir not_connectable_dir_; 413 TestExtensionDir not_connectable_dir_;
394 TestExtensionDir tls_channel_id_connectable_dir_; 414 TestExtensionDir tls_channel_id_connectable_dir_;
415 TestExtensionDir hosted_app_dir_;
395 }; 416 };
396 417
397 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, NotInstalled) { 418 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, NotInstalled) {
398 InitializeTestServer(); 419 InitializeTestServer();
399 420
400 const char kFakeId[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 421 const char kFakeId[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
401 422
402 ui_test_utils::NavigateToURL(browser(), chromium_org_url()); 423 ui_test_utils::NavigateToURL(browser(), chromium_org_url());
403 EXPECT_EQ(NAMESPACE_NOT_DEFINED, CanConnectAndSendMessages(kFakeId)); 424 EXPECT_EQ(NAMESPACE_NOT_DEFINED, CanConnectAndSendMessages(kFakeId));
404 EXPECT_FALSE(AreAnyNonWebApisDefined()); 425 EXPECT_FALSE(AreAnyNonWebApisDefined());
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 EXPECT_EQ("true", 910 EXPECT_EQ("true",
890 ExecuteScriptInBackgroundPage(sender->id(), 911 ExecuteScriptInBackgroundPage(sender->id(),
891 base::StringPrintf( 912 base::StringPrintf(
892 "chrome.test.runWithUserGesture(function() {\n" 913 "chrome.test.runWithUserGesture(function() {\n"
893 " chrome.runtime.sendMessage('%s', {}, function(response) {\n" 914 " chrome.runtime.sendMessage('%s', {}, function(response) {\n"
894 " window.domAutomationController.send('' + response.result);\n" 915 " window.domAutomationController.send('' + response.result);\n"
895 " });\n" 916 " });\n"
896 "});", receiver->id().c_str()))); 917 "});", receiver->id().c_str())));
897 } 918 }
898 919
920 // Tests that a hosted app on a connectable site doesn't interfere with the
921 // connectability of that site.
922 IN_PROC_BROWSER_TEST_F(ExternallyConnectableMessagingTest, HostedAppOnWebsite) {
923 InitializeTestServer();
924
925 LoadChromiumHostedApp();
926
927 // The presence of the hosted app shouldn't give the ability to send messages.
928 ui_test_utils::NavigateToURL(browser(), chromium_org_url());
929 EXPECT_EQ(NAMESPACE_NOT_DEFINED, CanConnectAndSendMessages(""));
930 EXPECT_FALSE(AreAnyNonWebApisDefined());
931
932 // Once a connectable extension is installed, it should.
933 const Extension* extension = LoadChromiumConnectableExtension();
934 EXPECT_EQ(OK, CanConnectAndSendMessages(extension->id()));
935 EXPECT_FALSE(AreAnyNonWebApisDefined());
936 }
937
899 } // namespace 938 } // namespace
900 }; // namespace extensions 939 }; // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/common/extensions/api/_api_features.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698