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

Side by Side Diff: chrome/test/data/webui/net_internals/prerender_view.js

Issue 7553009: Add some browser tests for net-internals (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Use g_browser.receive as function name when appropriate (Really, this time). 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
Property Changes:
Added: svn:eol-style
+ LF
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 /**
6 * Tries to prerender two pages, one that will fail and one that will succeed.
7 * Checks that we see all relevant events, and update the corresponding tables.
8 * The prerender that will fail will briefly be active before it fails. Having
9 * an active prerender will block another prerender from starting too soon, so
10 * |failureUrl| must be prerendered first.
11 */
12 netInternalsTest.test('NetInternalsPrerenderView',
13 function (failureUrl, successUrl) {
14 // IDs for special HTML elements in prerender_view.html
15 const HISTORY_DIV_ID = 'prerender-view-history-div';
16 const ACTIVE_DIV_ID = 'prerender-view-active-div';
17
18 // Phases of the test.
19 const STATE = {
20 // We've switched to the prerender tab, but have yet to receive the
21 // resulting onPrerenderInfoChanged event with no prerenders active or in
22 // the history.
23 START: 0,
24 // We've added the prefetch link for |failureUrl|. We may receive more
25 // than one event while in this state, as we may see it as active once
26 // or more before it moves to the history. We will not receive any
27 // event with both history and active prerenders empty in this state,
28 // as we only send notifications when the values change.
29 FAILURE_URL_LINKED: 1,
30 // We've added the prefetch link for |successUrl|.
31 SUCCESS_URL_LINKED: 2
32 };
33
34 /**
35 * Observer responsible for running the test and checking results.
36 */
Sheridan Rawlins 2011/08/03 18:29:57 @param
mmenke 2011/08/03 19:30:12 Done.
37 function PrerenderTestObserver(failureUrl, successUrl) {
38 // True if we've started prerendering |successUrl|.
39 this.startedSuccessfulPrerender_ = false;
40 this.failureUrl_ = failureUrl;
41 this.successUrl_ = successUrl;
42 this.state_ = STATE.START;
43 }
44
45 PrerenderTestObserver.prototype = {
46 /**
47 * Main function of the observer. Tracks state transitions, checks the
48 * table sizes, and does some sanity checking on received data.
49 */
50 onPrerenderInfoChanged: function(prerenderInfo) {
51 console.log('State: ' + this.state_);
52
53 // Verify that prerendering is enabled.
54 assertTrue(prerenderInfo.enabled, 'Prerendering not enabled.');
55
56 // Check number of rows in both tables.
57 netInternalsTest.checkStyledTableRows(HISTORY_DIV_ID,
58 prerenderInfo.history.length);
59 netInternalsTest.checkStyledTableRows(ACTIVE_DIV_ID,
60 prerenderInfo.active.length);
61
62 if (this.state_ == STATE.START) {
63 this.start_(prerenderInfo);
64 } else if (this.state_ == STATE.FAILURE_URL_LINKED) {
65 this.failureUrlLinked_(prerenderInfo);
66 } else if (this.state_ == STATE.SUCCESS_URL_LINKED) {
67 this.successUrlLinked_(prerenderInfo);
68 }
69 },
70
71 /**
72 * Start by triggering a prerender of |failureUrl_|.
73 * At this point, we expect no active or historical prerender entries.
74 */
Sheridan Rawlins 2011/08/03 18:29:57 @param
mmenke 2011/08/03 19:30:12 Done.
75 start_: function(prerenderInfo) {
76 expectEquals(0, prerenderInfo.active.length);
77 expectEquals(0, prerenderInfo.history.length);
78
79 // Adding the url we expect to fail.
80 addPrerenderLink(this.failureUrl_);
81 this.state_ = STATE.FAILURE_URL_LINKED;
82 },
83
84 /**
85 * We expect to either see the failure url as an active entry, or see it
86 * move straight to the history. In the latter case, we skip a state.
Sheridan Rawlins 2011/08/03 18:29:57 @param
mmenke 2011/08/03 19:30:12 Done.
87 */
88 failureUrlLinked_: function(prerenderInfo) {
89 // May see the failure url as active, or may see it move straight to the
90 // history. If not, skip to the next state.
91 if (prerenderInfo.active.length == 1) {
92 expectEquals(this.failureUrl_, prerenderInfo.active[0].url);
93 expectEquals(0, prerenderInfo.history.length);
94 return;
95 }
96
97 // The prerender of |failureUrl_| has been cancelled, and is now in the
98 // history. Go ahead and prerender |successUrl_|.
99 this.prerenderSuccessUrl_(prerenderInfo);
100 },
101
102 /**
103 * Prerender |successUrl_|. The prerender of |failureUrl_| should have
104 * failed, and it should now be in the history.
Sheridan Rawlins 2011/08/03 18:29:57 @param
mmenke 2011/08/03 19:30:12 Done.
105 */
106 prerenderSuccessUrl_: function(prerenderInfo) {
107 // We may see the duration of the active prerender increase. If so,
108 // do nothing.
109 if (prerenderInfo.active.length == 1)
110 return;
111
112 assertEquals(1, prerenderInfo.history.length);
113 expectEquals(this.failureUrl_, prerenderInfo.history[0].url);
114 expectEquals(0, prerenderInfo.active.length);
115
116 addPrerenderLink(this.successUrl_);
117 this.state_ = STATE.SUCCESS_URL_LINKED;
118 },
119
120 /**
121 * At this point, we expect to see the failure url in the history, and the
122 * successUrl in the active entry list, and the test is done.
123 */
124 successUrlLinked_: function(prerenderInfo) {
125 assertEquals(1, prerenderInfo.history.length);
126 expectEquals(this.failureUrl_, prerenderInfo.history[0].url);
127 assertEquals(1, prerenderInfo.active.length);
128 expectEquals(this.successUrl_, prerenderInfo.active[0].url);
129 netInternalsTest.testDone();
130 },
131 };
132
133 /**
134 * Adds a <link rel="prerender" href="url"> to the document.
Sheridan Rawlins 2011/08/03 18:29:57 @param
mmenke 2011/08/03 19:30:12 Done.
135 */
136 function addPrerenderLink(url) {
137 var link = document.createElement('link');
138 link.setAttribute('rel', 'prerender');
139 link.setAttribute('href', url);
140 document.body.appendChild(link);
141 }
142
143 netInternalsTest.switchToView('prerender');
144
145 // Create the test observer, which will start the test once we see the initial
146 // onPrerenderInfoChanged event from changing the active tab.
147 var prerenderObserver = new PrerenderTestObserver(failureUrl, successUrl);
148 g_browser.addPrerenderInfoObserver(prerenderObserver);
149 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698