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

Side by Side Diff: chrome/browser/resources/net_internals/browser_bridge.js

Issue 7553009: Add some browser tests for net-internals (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Just test result of first test Created 9 years, 4 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 | 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 /** 5 /**
6 * This class provides a "bridge" for communicating between the javascript and 6 * This class provides a "bridge" for communicating between the javascript and
7 * the browser. 7 * the browser.
8 */ 8 */
9 9
10 var BrowserBridge = (function() { 10 var BrowserBridge = (function() {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 this.sendGetPrerenderInfo.bind(this)); 59 this.sendGetPrerenderInfo.bind(this));
60 60
61 // NetLog entries are all sent to the |SourceTracker|, which both tracks 61 // NetLog entries are all sent to the |SourceTracker|, which both tracks
62 // them and manages its own observer list. 62 // them and manages its own observer list.
63 this.sourceTracker = new SourceTracker(); 63 this.sourceTracker = new SourceTracker();
64 64
65 // Setting this to true will cause messages from the browser to be ignored, 65 // Setting this to true will cause messages from the browser to be ignored,
66 // and no messages will be sent to the browser, either. Intended for use 66 // and no messages will be sent to the browser, either. Intended for use
67 // when viewing log files. 67 // when viewing log files.
68 this.disabled_ = false; 68 this.disabled_ = false;
69
70 // Interval id returned by window.setInterval for polling timer.
71 this.pollIntervalId_ = null;
69 } 72 }
70 73
71 cr.addSingletonGetter(BrowserBridge); 74 cr.addSingletonGetter(BrowserBridge);
72 75
73 BrowserBridge.prototype = { 76 BrowserBridge.prototype = {
74 77
75 //-------------------------------------------------------------------------- 78 //--------------------------------------------------------------------------
76 // Messages sent to the browser 79 // Messages sent to the browser
77 //-------------------------------------------------------------------------- 80 //--------------------------------------------------------------------------
78 81
79 /** 82 /**
80 * Wraps |chrome.send|. Doesn't send anything when disabled. 83 * Wraps |chrome.send|. Doesn't send anything when disabled.
81 */ 84 */
82 send: function(value1, value2) { 85 send: function(value1, value2) {
83 if (!this.disabled_) { 86 if (!this.disabled_) {
84 if (arguments.length == 1) { 87 if (arguments.length == 1) {
85 chrome.send(value1); 88 chrome.send(value1);
86 } else if (arguments.length == 2) { 89 } else if (arguments.length == 2) {
87 chrome.send(value1, value2); 90 chrome.send(value1, value2);
88 } else { 91 } else {
89 throw 'Unsupported number of arguments.'; 92 throw 'Unsupported number of arguments.';
90 } 93 }
91 } 94 }
92 }, 95 },
93 96
94 sendReady: function() { 97 sendReady: function() {
95 this.send('notifyReady'); 98 this.send('notifyReady');
99 this.setPollInterval(POLL_INTERVAL_MS);
100 },
96 101
97 // Some of the data we are interested is not currently exposed as a 102 /**
98 // stream, so we will poll the browser to find out when it changes and 103 * Some of the data we are interested is not currently exposed as a
99 // then notify the observers. 104 * stream. This starts polling those with active observers (visible
100 window.setInterval(this.checkForUpdatedInfo.bind(this, false), 105 * views) every |intervalMs|. Subsequent calls override previous calls
101 POLL_INTERVAL_MS); 106 * to this function. If |intervalMs| is 0, stops polling. Function only
107 * exposed for unit testing.
108 */
109 setPollInterval: function(intervalMs) {
110 if (this.pollIntervalId_ !== null) {
111 window.clearInterval(this.pollIntervalId_);
112 this.pollIntervalId_ = null;
113 }
114
115 if (intervalMs > 0) {
116 this.pollIntervalId_ =
117 window.setInterval(this.checkForUpdatedInfo.bind(this, false),
118 intervalMs);
119 }
102 }, 120 },
103 121
104 sendGetProxySettings: function() { 122 sendGetProxySettings: function() {
105 // The browser will call receivedProxySettings on completion. 123 // The browser will call receivedProxySettings on completion.
106 this.send('getProxySettings'); 124 this.send('getProxySettings');
107 }, 125 },
108 126
109 sendReloadProxySettings: function() { 127 sendReloadProxySettings: function() {
110 this.send('reloadProxySettings'); 128 this.send('reloadProxySettings');
111 }, 129 },
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 receivedPrerenderInfo: function(prerenderInfo) { 319 receivedPrerenderInfo: function(prerenderInfo) {
302 this.pollableDataHelpers_.prerenderInfo.update(prerenderInfo); 320 this.pollableDataHelpers_.prerenderInfo.update(prerenderInfo);
303 }, 321 },
304 322
305 //-------------------------------------------------------------------------- 323 //--------------------------------------------------------------------------
306 324
307 /** 325 /**
308 * Prevents receiving/sending events to/from the browser. 326 * Prevents receiving/sending events to/from the browser.
309 */ 327 */
310 disable: function() { 328 disable: function() {
311 this.disabled_ = true; 329 this.disabled_ = true;
eroman 2011/08/03 00:32:24 it might be a good idea to clear the polling inter
mmenke 2011/08/03 15:44:17 Good idea, done.
312 }, 330 },
313 331
314 /** 332 /**
315 * Adds a listener of the proxy settings. |observer| will be called back 333 * Adds a listener of the proxy settings. |observer| will be called back
316 * when data is received, through: 334 * when data is received, through:
317 * 335 *
318 * observer.onProxySettingsChanged(proxySettings) 336 * observer.onProxySettingsChanged(proxySettings)
319 * 337 *
320 * |proxySettings| is a dictionary with (up to) two properties: 338 * |proxySettings| is a dictionary with (up to) two properties:
321 * 339 *
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 helper.removeObserver(this); 641 helper.removeObserver(this);
624 --this.observingCount_; 642 --this.observingCount_;
625 this.updatedData_[name] = data; 643 this.updatedData_[name] = data;
626 if (this.observingCount_ == 0) 644 if (this.observingCount_ == 0)
627 this.callback_(this.updatedData_); 645 this.callback_(this.updatedData_);
628 } 646 }
629 }; 647 };
630 648
631 return BrowserBridge; 649 return BrowserBridge;
632 })(); 650 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698