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

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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 169
164 ASSERT_FALSE(destination.empty()); 170 ASSERT_FALSE(destination.empty());
165 ASSERT_EQ(destination, crx_path); 171 ASSERT_EQ(destination, crx_path);
166 172
167 test_crx_.push_back(destination); 173 test_crx_.push_back(destination);
168 } 174 }
169 175
170 std::vector<FilePath> test_crx_; 176 std::vector<FilePath> test_crx_;
171 }; 177 };
172 178
179 class ExtensionWebstoreGetWebGLStatusTest : public InProcessBrowserTest {
180 public:
181 void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
182 // In linux, we need to launch GPU process to decide if WebGL is allowed.
183 // Run it on top of osmesa to avoid bot driver issues.
184 #if defined(OS_LINUX)
185 CHECK(test_launcher_utils::OverrideGLImplementation(
186 command_line, gfx::kGLImplementationOSMesaName)) <<
187 "kUseGL must not be set multiple times!";
188 #endif
189 }
190
191 protected:
192 void RunTest(bool webgl_allowed) {
193 static const char kEmptyArgs[] = "[]";
194 static const char kWebGLStatusAllowed[] = "webgl_allowed";
195 static const char kWebGLStatusBlocked[] = "webgl_blocked";
196 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(
197 new GetWebGLStatusFunction(), kEmptyArgs, browser()));
198 EXPECT_EQ(base::Value::TYPE_STRING, result->GetType());
199 StringValue* value = static_cast<StringValue*>(result.get());
200 std::string webgl_status = "";
201 EXPECT_TRUE(value && value->GetAsString(&webgl_status));
202 EXPECT_STREQ(webgl_allowed ? kWebGLStatusAllowed : kWebGLStatusBlocked,
203 webgl_status.c_str());
204 }
205 };
206
173 // Test cases where the user accepts the install confirmation dialog. 207 // Test cases where the user accepts the install confirmation dialog.
174 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, InstallAccepted) { 208 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, InstallAccepted) {
175 ASSERT_TRUE(RunInstallTest("accepted.html", "extension.crx")); 209 ASSERT_TRUE(RunInstallTest("accepted.html", "extension.crx"));
176 } 210 }
177 211
178 // Tests passing a localized name. 212 // Tests passing a localized name.
179 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, InstallLocalized) { 213 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, InstallLocalized) {
180 ASSERT_TRUE(RunInstallTest("localized.html", "localized_extension.crx")); 214 ASSERT_TRUE(RunInstallTest("localized.html", "localized_extension.crx"));
181 } 215 }
182 216
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest, 256 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateApiTest,
223 IconUrl) { 257 IconUrl) {
224 ASSERT_TRUE(RunInstallTest("icon_url.html", "extension.crx")); 258 ASSERT_TRUE(RunInstallTest("icon_url.html", "extension.crx"));
225 } 259 }
226 260
227 // Tests using silentlyInstall to install extensions. 261 // Tests using silentlyInstall to install extensions.
228 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateBundleTest, SilentlyInstall) { 262 IN_PROC_BROWSER_TEST_F(ExtensionWebstorePrivateBundleTest, SilentlyInstall) {
229 WebstorePrivateApi::SetTrustTestIDsForTesting(true); 263 WebstorePrivateApi::SetTrustTestIDsForTesting(true);
230 ASSERT_TRUE(RunPageTest(GetTestServerURL("silently_install.html").spec())); 264 ASSERT_TRUE(RunPageTest(GetTestServerURL("silently_install.html").spec()));
231 } 265 }
266
267 // Tests getWebGLStatus function when WebGL is allowed.
268 IN_PROC_BROWSER_TEST_F(ExtensionWebstoreGetWebGLStatusTest, Allowed) {
269 bool webgl_allowed = true;
270 RunTest(webgl_allowed);
271 }
272
273 // Tests getWebGLStatus function when WebGL is blacklisted.
274 IN_PROC_BROWSER_TEST_F(ExtensionWebstoreGetWebGLStatusTest, Blocked) {
275 static const std::string json_blacklist =
276 "{\n"
277 " \"name\": \"gpu blacklist\",\n"
278 " \"version\": \"1.0\",\n"
279 " \"entries\": [\n"
280 " {\n"
281 " \"id\": 1,\n"
282 " \"blacklist\": [\n"
283 " \"webgl\"\n"
284 " ]\n"
285 " }\n"
286 " ]\n"
287 "}";
288 scoped_ptr<Version> os_version(Version::GetVersionFromString("1.0"));
289 GpuBlacklist* blacklist = new GpuBlacklist("1.0");
290
291 ASSERT_TRUE(blacklist->LoadGpuBlacklist(
292 json_blacklist, GpuBlacklist::kAllOs));
293 GpuDataManager::GetInstance()->SetGpuBlacklist(blacklist);
294 GpuFeatureFlags flags = GpuDataManager::GetInstance()->GetGpuFeatureFlags();
295 EXPECT_EQ(
296 flags.flags(), static_cast<uint32>(GpuFeatureFlags::kGpuFeatureWebgl));
297
298 bool webgl_allowed = false;
299 RunTest(webgl_allowed);
300 }
301
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