Index: chrome/test/data/webui/net_internals/prerender_view.js |
diff --git a/chrome/test/data/webui/net_internals/prerender_view.js b/chrome/test/data/webui/net_internals/prerender_view.js |
index 6240b1d6e57ff88ff17fe43d16be5c9a704deb6c..a29c3329b03ae667a7bc9a6d42866a15ee5c6064 100644 |
--- a/chrome/test/data/webui/net_internals/prerender_view.js |
+++ b/chrome/test/data/webui/net_internals/prerender_view.js |
@@ -3,12 +3,11 @@ |
// found in the LICENSE file. |
/** |
- * Tries to prerender a page. |shouldSucceed| indicates whether the prerender |
- * is expected to succeed or not. If it's false, we just wait for the page |
- * to fail, possibly seeing it as active first. If it's true, we open the |
- * URL in another tab. This is done via a message to the test handler, rather |
- * than via Javascript, so we don't cancel the prerender since prerendering |
- * can't currently set window.opener properly. |
+ * Tries to prerender a page. A loader page is opened in a background tab, |
+ * which triggers the prerender as well as has a link to it. |shouldSucceed| |
+ * indicates whether the prerender is expected to succeed or not. |
+ * If it's false, we just wait for the page to fail, possibly seeing it as |
+ * active first. If it's true, we navigate to the URL in the background tab. |
* |
* Checks that we see all relevant events, and update the corresponding tables. |
* In both cases, we exit the test once we see the prerender in the history. |
@@ -16,36 +15,39 @@ |
* history. |
*/ |
netInternalsTest.test('netInternalsPrerenderView', |
- function (url, shouldSucceed, finalStatus) { |
+ function (url, loaderUrl, shouldSucceed, finalStatus) { |
// Phases of the test. |
const STATE = { |
// We've switched to the prerender tab, but have yet to receive the |
// resulting onPrerenderInfoChanged event with no prerenders active or in |
// the history. |
START: 0, |
- // We've added the prerender link, but still need to open the link in a new |
- // tab. Only visit this state if |shouldSucceed| is true. |
- NEED_OPEN_IN_NEW_TAB: 1, |
- // We've added the prefetch link for |url|, opened a new tab if needed, |
- // and are waiting for it to move to the history. We may see the prerender |
- // one or more times in the active list, or it may move straight to the |
- // history. We will not receive any event with both history and active |
- // prerenders empty while in this state, as we only send notifications |
- // when the values change. |
+ // We're waiting for the prerender loader to start in a background tab, |
+ // as well as the prerendered view to be created. Only visit this state if |
+ // |shouldSucceed| is true. |
+ NEED_NAVIGATE: 1, |
+ // The prerendered view has been created, and we've started the navigation |
+ // to it. We're waiting for it to move to the history. We may see the |
+ // prerender one or more times in the active list, or it may move straight |
+ // to the history. We will not receive any event with both history and |
+ // active prerenders empty while in this state, as we only send |
+ // notifications when the values change. |
HISTORY_WAIT: 2 |
}; |
/** |
* Observer responsible for running the test and checking results. |
* @param {string} url URL to be prerendered. |
+ * @param {string} loaderUrl URL to trigger the prerender. |
* @param {string} shouldSucceed Whether or not the prerender should succeed. |
* @param {string} finalStatus The expected value of |final_status|. |
* @constructor |
*/ |
- function PrerenderTestObserver(url, shouldSucceed, finalStatus) { |
+ function PrerenderTestObserver(url, loaderUrl, shouldSucceed, finalStatus) { |
// True if we've started prerendering |successUrl|. |
this.startedSuccessfulPrerender_ = false; |
this.url_ = url; |
+ this.loaderUrl_ = loaderUrl; |
this.shouldSucceed_ = shouldSucceed; |
this.finalStatus_ = finalStatus; |
this.state_ = STATE.START; |
@@ -69,45 +71,39 @@ netInternalsTest.test('netInternalsPrerenderView', |
if (this.state_ == STATE.START) { |
this.start_(prerenderInfo); |
- } else if (this.state_ == STATE.NEED_OPEN_IN_NEW_TAB) { |
- this.openInNewTab_(prerenderInfo); |
+ } else if (this.state_ == STATE.NEED_NAVIGATE) { |
+ this.navigate_(prerenderInfo); |
} else if (this.state_ == STATE.HISTORY_WAIT) { |
this.checkDone_(prerenderInfo); |
} |
}, |
/** |
- * Start by triggering a prerender of |url_|. |
+ * Start by triggering a prerender of |url_| in a background tab. |
* At this point, we expect no active or historical prerender entries. |
* @param {Object} prerenderInfo State of prerendering pages. |
*/ |
start_: function(prerenderInfo) { |
expectEquals(0, prerenderInfo.active.length); |
expectEquals(0, prerenderInfo.history.length); |
- |
- // Adding the url we expect to fail. |
- addPrerenderLink(this.url_); |
+ chrome.send('openNewTab', [this.loaderUrl_]); |
if (this.shouldSucceed_) { |
- this.state_ = STATE.NEED_OPEN_IN_NEW_TAB; |
+ this.state_ = STATE.NEED_NAVIGATE; |
} else { |
this.state_ = STATE.HISTORY_WAIT; |
} |
}, |
/** |
- * Starts opening |url_| in a new tab. |
- * At this point, we expect the prerender to be active. |
- * Only called if |shouldSucceed_| is true, and |urlOpenedInNewTab_| is |
- * false. |
+ * Navigate to the prerendered page in the background tab. |
* @param {Object} prerenderInfo State of prerendering pages. |
*/ |
- openInNewTab_: function(prerenderInfo) { |
+ navigate_: function(prerenderInfo) { |
expectEquals(0, prerenderInfo.history.length); |
assertEquals(1, prerenderInfo.active.length); |
expectEquals(this.url_, prerenderInfo.active[0].url); |
expectTrue(this.shouldSucceed_); |
- |
- chrome.send('openNewTab', [this.url_]); |
+ chrome.send('navigateToPrerender'); |
this.state_ = STATE.HISTORY_WAIT; |
}, |
@@ -142,22 +138,11 @@ netInternalsTest.test('netInternalsPrerenderView', |
} |
}; |
- /** |
- * Adds a <link rel="prerender" href="url"> to the document. |
- * @param {string} url URL of the page to prerender. |
- */ |
- function addPrerenderLink(url) { |
- var link = document.createElement('link'); |
- link.setAttribute('rel', 'prerender'); |
- link.setAttribute('href', url); |
- document.body.appendChild(link); |
- } |
- |
netInternalsTest.switchToView('prerender'); |
// Create the test observer, which will start the test once we see the initial |
// onPrerenderInfoChanged event from changing the active tab. |
- var prerenderObserver = new PrerenderTestObserver(url, shouldSucceed, |
- finalStatus); |
+ var prerenderObserver = new PrerenderTestObserver(url, loaderUrl, |
+ shouldSucceed, finalStatus); |
g_browser.addPrerenderInfoObserver(prerenderObserver, true); |
}); |