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

Side by Side Diff: chrome/test/data/extensions/api_test/native_bindings/background.js

Issue 2615773002: [Extensions Bindings] Add enum support (Closed)
Patch Set: rebase Created 3 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
« no previous file with comments | « no previous file | extensions/renderer/api_binding.h » ('j') | extensions/renderer/api_binding.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 if (!chrome || !chrome.test) 5 if (!chrome || !chrome.test)
6 throw new Error('chrome.test is undefined'); 6 throw new Error('chrome.test is undefined');
7 7
8 // This is a good end-to-end test for two reasons. The first is obvious - it 8 // This is a good end-to-end test for two reasons. The first is obvious - it
9 // tests a simple API and makes sure it behaves as expected, as well as testing 9 // tests a simple API and makes sure it behaves as expected, as well as testing
10 // that other APIs are unavailable. 10 // that other APIs are unavailable.
11 // The second is that chrome.test is itself an extension API, and a rather 11 // The second is that chrome.test is itself an extension API, and a rather
12 // complex one. It requires both traditional bindings (renderer parses args, 12 // complex one. It requires both traditional bindings (renderer parses args,
13 // passes info to browser process, browser process does work and responds, re- 13 // passes info to browser process, browser process does work and responds, re-
14 // enters JS) and custom JS bindings (in order to have our runTests, assert* 14 // enters JS) and custom JS bindings (in order to have our runTests, assert*
15 // methods, etc). If any of these stages failed, the test itself would also 15 // methods, etc). If any of these stages failed, the test itself would also
16 // fail. 16 // fail.
17 chrome.test.runTests([ 17 chrome.test.runTests([
18 function idleApi() { 18 function idleApi() {
19 chrome.test.assertTrue(!!chrome.idle); 19 chrome.test.assertTrue(!!chrome.idle);
20 chrome.test.assertTrue(!!chrome.idle.IdleState);
21 chrome.test.assertTrue(!!chrome.idle.IdleState.IDLE);
22 chrome.test.assertTrue(!!chrome.idle.IdleState.ACTIVE);
20 chrome.test.assertTrue(!!chrome.idle.queryState); 23 chrome.test.assertTrue(!!chrome.idle.queryState);
21 chrome.idle.queryState(1000, function(state) { 24 chrome.idle.queryState(1000, function(state) {
22 // Depending on the machine, this could come back as either idle or 25 // Depending on the machine, this could come back as either idle or
23 // active. However, all we're curious about is the bindings themselves 26 // active. However, all we're curious about is the bindings themselves
24 // (not the API implementation), so as long as it's a possible response, 27 // (not the API implementation), so as long as it's a possible response,
25 // it's a success for our purposes. 28 // it's a success for our purposes.
26 // TODO(devlin): Update this to use chrome.idle.IdleState.[ACTIVE|IDLE] 29 chrome.test.assertTrue(state == chrome.idle.IdleState.IDLE ||
27 // when we have enums in native bindings. 30 state == chrome.idle.IdleState.ACTIVE);
28 chrome.test.assertTrue(state == 'idle' || state == 'active', state);
29 chrome.test.succeed(); 31 chrome.test.succeed();
30 }); 32 });
31 }, 33 },
32 function nonexistentApi() { 34 function nonexistentApi() {
33 chrome.test.assertFalse(!!chrome.nonexistent); 35 chrome.test.assertFalse(!!chrome.nonexistent);
34 chrome.test.succeed(); 36 chrome.test.succeed();
35 }, 37 },
36 function disallowedApi() { 38 function disallowedApi() {
37 chrome.test.assertFalse(!!chrome.power); 39 chrome.test.assertFalse(!!chrome.power);
38 chrome.test.succeed(); 40 chrome.test.succeed();
39 }, 41 },
40 ]); 42 ]);
OLDNEW
« no previous file with comments | « no previous file | extensions/renderer/api_binding.h » ('j') | extensions/renderer/api_binding.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698