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

Side by Side Diff: chrome/browser/extensions/api/runtime/runtime_apitest.cc

Issue 264743014: Move chrome.runtime to //extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: prevent runtime impl from handling invalid update versions Created 6 years, 7 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/apps/app_browsertest_util.h"
6 #include "chrome/browser/extensions/api/management/management_api.h"
7 #include "chrome/browser/extensions/api/runtime/runtime_api.h"
8 #include "chrome/browser/extensions/extension_apitest.h"
9 #include "chrome/browser/extensions/extension_function_test_utils.h"
10 #include "chrome/browser/extensions/test_extension_dir.h"
11 #include "chrome/test/base/ui_test_utils.h"
12 #include "content/public/browser/notification_service.h"
13 #include "extensions/browser/extension_registry.h"
14 #include "net/test/embedded_test_server/embedded_test_server.h"
15
16 // Tests the privileged components of chrome.runtime.
17 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeRuntimePrivileged) {
18 ASSERT_TRUE(RunExtensionTest("runtime/privileged")) << message_;
19 }
20
21 // Tests the unprivileged components of chrome.runtime.
22 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeRuntimeUnprivileged) {
23 ASSERT_TRUE(StartEmbeddedTestServer());
24 ASSERT_TRUE(
25 LoadExtension(test_data_dir_.AppendASCII("runtime/content_script")));
26
27 // The content script runs on webpage.html.
28 ResultCatcher catcher;
29 ui_test_utils::NavigateToURL(browser(),
30 embedded_test_server()->GetURL("/webpage.html"));
31 EXPECT_TRUE(catcher.GetNextResult()) << message_;
32 }
33
34 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeRuntimeUninstallURL) {
35 // Auto-confirm the uninstall dialog.
36 extensions::ManagementUninstallFunction::SetAutoConfirmForTest(true);
37 ASSERT_TRUE(LoadExtension(
38 test_data_dir_.AppendASCII("runtime").AppendASCII("uninstall_url").
39 AppendASCII("sets_uninstall_url")));
40 ASSERT_TRUE(RunExtensionTest("runtime/uninstall_url")) << message_;
41 }
42
43 namespace extensions {
44
45 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ChromeRuntimeGetPlatformInfo) {
46 scoped_ptr<base::Value> result(
47 extension_function_test_utils::RunFunctionAndReturnSingleResult(
48 new RuntimeGetPlatformInfoFunction(),
49 "[]",
50 browser()));
51 ASSERT_TRUE(result.get() != NULL);
52 base::DictionaryValue* dict =
53 extension_function_test_utils::ToDictionary(result.get());
54 ASSERT_TRUE(dict != NULL);
55 EXPECT_TRUE(dict->HasKey("os"));
56 EXPECT_TRUE(dict->HasKey("arch"));
57 EXPECT_TRUE(dict->HasKey("nacl_arch"));
58 }
59
60 // Tests chrome.runtime.getPackageDirectory with an app.
61 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest,
62 ChromeRuntimeGetPackageDirectoryEntryApp) {
63 ClearCommandLineArgs();
64 ASSERT_TRUE(RunPlatformAppTest("api_test/runtime/get_package_directory/app"))
65 << message_;
66 }
67
68 // Tests chrome.runtime.getPackageDirectory with an extension.
69 IN_PROC_BROWSER_TEST_F(ExtensionApiTest,
70 ChromeRuntimeGetPackageDirectoryEntryExtension) {
71 ASSERT_TRUE(RunExtensionTest("runtime/get_package_directory/extension"))
72 << message_;
73 }
74
75 // Tests chrome.runtime.reload
76 // This test is flaky on Linux: crbug.com/366181
77 #if defined(OS_LINUX) || defined(OS_CHROMEOS)
78 #define MAYBE_ChromeRuntimeReload DISABLED_ChromeRuntimeReload
79 #else
80 #define MAYBE_ChromeRuntimeReload ChromeRuntimeReload
81 #endif
82 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_ChromeRuntimeReload) {
83 ExtensionRegistry* registry = ExtensionRegistry::Get(profile());
84 const char kManifest[] =
85 "{"
86 " \"name\": \"reload\","
87 " \"version\": \"1.0\","
88 " \"background\": {"
89 " \"scripts\": [\"background.js\"]"
90 " },"
91 " \"manifest_version\": 2"
92 "}";
93
94 TestExtensionDir dir;
95 dir.WriteManifest(kManifest);
96 dir.WriteFile(FILE_PATH_LITERAL("background.js"), "console.log('loaded');");
97
98 const Extension* extension = LoadExtension(dir.unpacked_path());
99 ASSERT_TRUE(extension);
100 const std::string extension_id = extension->id();
101
102 // Somewhat arbitrary upper limit of 30 iterations. If the extension manages
103 // to reload itself that often without being terminated, the test fails
104 // anyway.
105 for (int i = 0; i < 30; i++) {
106 content::WindowedNotificationObserver unload_observer(
107 chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
108 content::NotificationService::AllSources());
109 content::WindowedNotificationObserver load_observer(
110 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
111 content::NotificationService::AllSources());
112
113 ASSERT_TRUE(ExecuteScriptInBackgroundPageNoWait(
114 extension_id, "chrome.runtime.reload();"));
115 unload_observer.Wait();
116
117 if (registry->GetExtensionById(extension_id,
118 ExtensionRegistry::TERMINATED)) {
119 break;
120 } else {
121 load_observer.Wait();
122 WaitForExtensionViewsToLoad();
123 }
124 }
125 ASSERT_TRUE(
126 registry->GetExtensionById(extension_id, ExtensionRegistry::TERMINATED));
127 }
128
129 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698