| OLD | NEW |
| 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 var portNumber; | 8 var portNumber; |
| 9 | 9 |
| 10 // This is a good end-to-end test for two reasons. The first is obvious - it | 10 // This is a good end-to-end test for two reasons. The first is obvious - it |
| 11 // tests a simple API and makes sure it behaves as expected, as well as testing | 11 // tests a simple API and makes sure it behaves as expected, as well as testing |
| 12 // that other APIs are unavailable. | 12 // that other APIs are unavailable. |
| 13 // The second is that chrome.test is itself an extension API, and a rather | 13 // The second is that chrome.test is itself an extension API, and a rather |
| 14 // complex one. It requires both traditional bindings (renderer parses args, | 14 // complex one. It requires both traditional bindings (renderer parses args, |
| 15 // passes info to browser process, browser process does work and responds, re- | 15 // passes info to browser process, browser process does work and responds, re- |
| 16 // enters JS) and custom JS bindings (in order to have our runTests, assert* | 16 // enters JS) and custom JS bindings (in order to have our runTests, assert* |
| 17 // methods, etc). If any of these stages failed, the test itself would also | 17 // methods, etc). If any of these stages failed, the test itself would also |
| 18 // fail. | 18 // fail. |
| 19 var tests = [ | 19 var tests = [ |
| 20 function idleApi() { | 20 function historyApi() { |
| 21 chrome.test.assertTrue(!!chrome.idle); | 21 chrome.test.assertTrue(!!chrome.history); |
| 22 chrome.test.assertTrue(!!chrome.idle.IdleState); | 22 chrome.test.assertTrue(!!chrome.history.TransitionType); |
| 23 chrome.test.assertTrue(!!chrome.idle.IdleState.IDLE); | 23 chrome.test.assertTrue(!!chrome.history.TransitionType.LINK); |
| 24 chrome.test.assertTrue(!!chrome.idle.IdleState.ACTIVE); | 24 chrome.test.assertTrue(!!chrome.history.TransitionType.TYPED); |
| 25 chrome.test.assertTrue(!!chrome.idle.queryState); | 25 chrome.test.assertTrue(!!chrome.history.getVisits); |
| 26 chrome.idle.queryState(1000, function(state) { | 26 chrome.history.getVisits({url: 'http://example.com'}, function(visits) { |
| 27 // Depending on the machine, this could come back as either idle or | 27 // We're just testing the bindings, not the history API, so we don't |
| 28 // active. However, all we're curious about is the bindings themselves | 28 // care about the response. |
| 29 // (not the API implementation), so as long as it's a possible response, | 29 chrome.test.assertTrue(!!visits); |
| 30 // it's a success for our purposes. | |
| 31 chrome.test.assertTrue(state == chrome.idle.IdleState.IDLE || | |
| 32 state == chrome.idle.IdleState.ACTIVE); | |
| 33 chrome.test.succeed(); | 30 chrome.test.succeed(); |
| 34 }); | 31 }); |
| 35 }, | 32 }, |
| 36 function nonexistentApi() { | 33 function nonexistentApi() { |
| 37 chrome.test.assertFalse(!!chrome.nonexistent); | 34 chrome.test.assertFalse(!!chrome.nonexistent); |
| 38 chrome.test.succeed(); | 35 chrome.test.succeed(); |
| 39 }, | 36 }, |
| 40 function disallowedApi() { | 37 function disallowedApi() { |
| 41 chrome.test.assertFalse(!!chrome.power); | 38 chrome.test.assertFalse(!!chrome.power); |
| 42 chrome.test.succeed(); | 39 chrome.test.succeed(); |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 }); | 322 }); |
| 326 }, | 323 }, |
| 327 ]; | 324 ]; |
| 328 | 325 |
| 329 chrome.test.getConfig(config => { | 326 chrome.test.getConfig(config => { |
| 330 chrome.test.assertTrue(!!config, 'config does not exist'); | 327 chrome.test.assertTrue(!!config, 'config does not exist'); |
| 331 chrome.test.assertTrue(!!config.testServer, 'testServer does not exist'); | 328 chrome.test.assertTrue(!!config.testServer, 'testServer does not exist'); |
| 332 portNumber = config.testServer.port; | 329 portNumber = config.testServer.port; |
| 333 chrome.test.runTests(tests); | 330 chrome.test.runTests(tests); |
| 334 }); | 331 }); |
| OLD | NEW |