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

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

Issue 8725019: Move another bunch of extension API tests to manifest_version 2. (Closed) Base URL: svn://svn.chromium.org/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
(Empty)
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
3 // found in the LICENSE file.
4
5 var failed = false;
6
7 function did_fail() {
8 return failed;
9 }
10
11 function set_failed(val) {
12 failed = val;
13 }
14
15 function fail() {
16 set_failed(true);
17 if (!did_fail()) {
18 chrome.test.fail();
19 }
20 }
21
22 var test_url = "http://localhost:PORT/files/extensions/test_file.html";
23
24 // For running in normal chrome (ie outside of the browser_tests environment),
25 // set debug to 1 here.
26 var debug = 0;
27 if (debug) {
28 test_url = "http://www.google.com";
29 chrome.test.log = function(msg) { console.log(msg) };
30 chrome.test.runTests = function(tests) {
31 for (var i in tests) {
32 tests[i]();
33 }
34 };
35 chrome.test.succeed = function(){ console.log("succeed"); };
36 chrome.test.fail = function(){ console.log("fail"); };
37 }
38
39 function runTests() {
40 chrome.test.runTests([
41 function test1() {
42 chrome.extension.onRequest.addListener(function(req, sender) {
43 chrome.test.log("got request: " + JSON.stringify(req));
44 if (req == "fail") {
45 fail();
46 } else if (req == "content_script_start") {
47 var tab = sender.tab;
48 if (tab.url.indexOf("#") != -1) {
49 fail();
50 } else {
51 chrome.tabs.update(tab.id, {"url": tab.url + "#foo"});
52 }
53 }
54 });
55 chrome.tabs.onUpdated.addListener(function(tabid, info, tab) {
56 chrome.test.log("onUpdated status: " + info.status + " url:" + tab.url);
57 if (info.status == "complete" && tab.url.indexOf("#foo") != -1) {
58 setTimeout(function() {
59 if (!did_fail()) {
60 chrome.test.succeed();
61 }
62 }, 750);
63 }
64 });
65 chrome.test.log("creating tab");
66 chrome.tabs.create({"url": test_url});
67 }
68 ]);
69 }
70
71 if (debug) {
72 runTests();
73 } else {
74 chrome.test.getConfig(function(config) {
75 test_url = test_url.replace(/PORT/, config.testServer.port);
76 runTests();
77 });
78 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698