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

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

Issue 8772031: Add a JS API for detecting WebGL availability. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years 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
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 <vector> 5 #include <vector>
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "chrome/browser/extensions/extension_apitest.h" 10 #include "chrome/browser/extensions/extension_apitest.h"
11 #include "chrome/browser/extensions/extension_function_test_utils.h"
11 #include "chrome/browser/extensions/extension_install_dialog.h" 12 #include "chrome/browser/extensions/extension_install_dialog.h"
12 #include "chrome/browser/extensions/extension_install_ui.h" 13 #include "chrome/browser/extensions/extension_install_ui.h"
13 #include "chrome/browser/extensions/extension_service.h" 14 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/extensions/extension_webstore_private_api.h" 15 #include "chrome/browser/extensions/extension_webstore_private_api.h"
15 #include "chrome/browser/extensions/webstore_installer.h" 16 #include "chrome/browser/extensions/webstore_installer.h"
16 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/ui/browser.h" 18 #include "chrome/browser/ui/browser.h"
18 #include "chrome/common/chrome_notification_types.h" 19 #include "chrome/common/chrome_notification_types.h"
19 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
21 #include "chrome/test/base/test_launcher_utils.h"
20 #include "chrome/test/base/ui_test_utils.h" 22 #include "chrome/test/base/ui_test_utils.h"
23 #include "content/browser/gpu/gpu_blacklist.h"
21 #include "content/public/browser/notification_observer.h" 24 #include "content/public/browser/notification_observer.h"
22 #include "content/public/browser/notification_registrar.h" 25 #include "content/public/browser/notification_registrar.h"
23 #include "net/base/mock_host_resolver.h" 26 #include "net/base/mock_host_resolver.h"
27 #include "ui/gfx/gl/gl_switches.h"
28
29 using namespace extension_function_test_utils;
24 30
25 namespace { 31 namespace {
26 32
27 class WebstoreInstallListener : public WebstoreInstaller::Delegate { 33 class WebstoreInstallListener : public WebstoreInstaller::Delegate {
28 public: 34 public:
29 WebstoreInstallListener() 35 WebstoreInstallListener()
30 : received_failure_(false), received_success_(false), waiting_(false) {} 36 : received_failure_(false), received_success_(false), waiting_(false) {}
31 37
32 void OnExtensionInstallSuccess(const std::string& id) OVERRIDE; 38 void OnExtensionInstallSuccess(const std::string& id) OVERRIDE;
33 void OnExtensionInstallFailure(const std::string& id, 39 void OnExtensionInstallFailure(const std::string& id,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 85
80 } // namespace 86 } // namespace
81 87
82 // A base class for tests below. 88 // A base class for tests below.
83 class ExtensionWebstorePrivateApiTest : public ExtensionApiTest { 89 class ExtensionWebstorePrivateApiTest : public ExtensionApiTest {
84 public: 90 public:
85 void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 91 void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
86 ExtensionApiTest::SetUpCommandLine(command_line); 92 ExtensionApiTest::SetUpCommandLine(command_line);
87 command_line->AppendSwitchASCII(switches::kAppsGalleryURL, 93 command_line->AppendSwitchASCII(switches::kAppsGalleryURL,
88 "http://www.example.com"); 94 "http://www.example.com");
95
96 // In linux, we need to launch GPU process to decide if WebGL is allowed.
Mihai Parparita -not on Chrome 2011/12/08 22:30:40 This can be removed, since you're no longer testin
97 // Run it on top of osmesa to avoid bot driver issues.
98 #if defined(OS_LINUX)
99 CHECK(test_launcher_utils::OverrideGLImplementation(
100 command_line, gfx::kGLImplementationOSMesaName)) <<
101 "kUseGL must not be set multiple times!";
102 #endif
89 } 103 }
90 104
91 void SetUpInProcessBrowserTestFixture() OVERRIDE { 105 void SetUpInProcessBrowserTestFixture() OVERRIDE {
92 // Start up the test server and get us ready for calling the install 106 // Start up the test server and get us ready for calling the install
93 // API functions. 107 // API functions.
94 host_resolver()->AddRule("www.example.com", "127.0.0.1"); 108 host_resolver()->AddRule("www.example.com", "127.0.0.1");
95 ASSERT_TRUE(test_server()->Start()); 109 ASSERT_TRUE(test_server()->Start());
96 SetExtensionInstallDialogAutoConfirmForTests(true); 110 SetExtensionInstallDialogAutoConfirmForTests(true);
97 ExtensionInstallUI::DisableFailureUIForTests(); 111 ExtensionInstallUI::DisableFailureUIForTests();
98 } 112 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 177
164 ASSERT_FALSE(destination.empty()); 178 ASSERT_FALSE(destination.empty());
165 ASSERT_EQ(destination, crx_path); 179 ASSERT_EQ(destination, crx_path);
166 180
167 test_crx_.push_back(destination); 181 test_crx_.push_back(destination);
168 } 182 }
169 183
170 std::vector<FilePath> test_crx_; 184 std::vector<FilePath> test_crx_;
171 }; 185 };
172 186
187 class ExtensionWebstoreGetWebGLStatusTest : public InProcessBrowserTest {
188 public:
189 void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
190 // In linux, we need to launch GPU process to decide if WebGL is allowed.
191 // Run it on top of osmesa to avoid bot driver issues.
192 #if defined(OS_LINUX)
193 CHECK(test_launcher_utils::OverrideGLImplementation(
194 command_line, gfx::kGLImplementationOSMesaName)) <<
195 "kUseGL must not be set multiple times!";
196 #endif
197 }
198
199 protected:
200 void RunTest(bool webgl_allowed) {
201 static const char kEmptyArgs[] = "[]";
202 static const char kWebGLStatusAllowed[] = "webgl_allowed";
203 static const char kWebGLStatusBlocked[] = "webgl_blocked";
204 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
205 new GetWebGLStatusFunction(), kEmptyArgs, browser()));
206 EXPECT_EQ(base::Value::TYPE_STRING, result->GetType());
207 StringValue* value = static_cast<StringValue*>(result.get());
208 std::string webgl_status = "";
209 EXPECT_TRUE(value && value->GetAsString(&webgl_status));
210 EXPECT_STREQ(webgl_allowed ? kWebGLStatusAllowed : kWebGLStatusBlocked,
211 webgl_status.c_str());
212 }
213
214 };
215
173 // Test cases where the user accepts the install confirmation dialog. 216 // Test cases where the user accepts the install confirmation dialog.
174 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, InstallAccepted) { 217 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, InstallAccepted) {
175 ASSERT_TRUE(RunInstallTest("accepted.html", "extension.crx")); 218 ASSERT_TRUE(RunInstallTest("accepted.html", "extension.crx"));
176 } 219 }
177 220
178 // Tests passing a localized name. 221 // Tests passing a localized name.
179 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, InstallLocalized) { 222 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, InstallLocalized) {
180 ASSERT_TRUE(RunInstallTest("localized.html", "localized_extension.crx")); 223 ASSERT_TRUE(RunInstallTest("localized.html", "localized_extension.crx"));
181 } 224 }
182 225
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, 265 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest,
223 IconUrl) { 266 IconUrl) {
224 ASSERT_TRUE(RunInstallTest("icon_url.html", "extension.crx")); 267 ASSERT_TRUE(RunInstallTest("icon_url.html", "extension.crx"));
225 } 268 }
226 269
227 // Tests using silentlyInstall to install extensions. 270 // Tests using silentlyInstall to install extensions.
228 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateBundleTest, SilentlyInstall) { 271 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateBundleTest, SilentlyInstall) {
229 WebstorePrivateApi::SetTrustTestIDsForTesting(true); 272 WebstorePrivateApi::SetTrustTestIDsForTesting(true);
230 ASSERT_TRUE(RunPageTest(GetTestServerURL("silently_install.html").spec())); 273 ASSERT_TRUE(RunPageTest(GetTestServerURL("silently_install.html").spec()));
231 } 274 }
275
276 // Tests getWebGLStatus function when WebGL is allowed.
277 IN_PROC_BROWSER_TEST_F(ExtensionWebstoreGetWebGLStatusTest, Allowed) {
278 bool webgl_allowed = true;
279 RunTest(webgl_allowed);
280 }
281
282 // Tests getWebGLStatus function when WebGL is blacklisted.
283 IN_PROC_BROWSER_TEST_F(ExtensionWebstoreGetWebGLStatusTest, Blocked) {
284 static const std::string json_blacklist =
285 "{\n"
286 " \"name\": \"gpu blacklist\",\n"
287 " \"version\": \"1.0\",\n"
288 " \"entries\": [\n"
289 " {\n"
290 " \"id\": 1,\n"
291 " \"blacklist\": [\n"
292 " \"webgl\"\n"
293 " ]\n"
294 " }\n"
295 " ]\n"
296 "}";
297 scoped_ptr<Version> os_version(Version::GetVersionFromString("1.0"));
298 GpuBlacklist* blacklist = new GpuBlacklist("1.0");
299
300 ASSERT_TRUE(blacklist->LoadGpuBlacklist(
301 json_blacklist, GpuBlacklist::kAllOs));
302 GpuDataManager::GetInstance()->SetGpuBlacklist(blacklist);
303 GpuFeatureFlags flags = GpuDataManager::GetInstance()->GetGpuFeatureFlags();
304 EXPECT_EQ(
305 flags.flags(), static_cast<uint32>(GpuFeatureFlags::kGpuFeatureWebgl));
306
307 bool webgl_allowed = false;
308 RunTest(webgl_allowed);
309 }
310
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_webstore_private_api.cc ('k') | chrome/common/extensions/api/extension_api.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698