Upstream version 5.34.98.0
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / platform_apps / ad_view / loadcommit_event / chrometest.js
1 // Copyright 2013 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 // This test checks the "loadcommit" event is called when the page inside an
6 // <adview> is loaded.
7
8 function runTests(guestURL) {
9   chrome.test.runTests([
10     function test() {
11       var adview = document.getElementsByTagName("adview")[0];
12
13       var onLoadCommit = function(event) {
14         var isTopLevel = event.isTopLevel;
15         if (!isTopLevel)
16           return;
17         var url = event.url;
18         chrome.test.assertEq(guestURL, url);
19         console.log("loadcommit event called: url=" + url);
20         adview.removeEventListener("loadcommit", onLoadCommit);
21         chrome.test.succeed();
22       };
23
24       adview.addEventListener("loadcommit", onLoadCommit);
25
26       adview.setAttribute("src", guestURL);
27     }
28   ]);
29 }
30
31 window.onload = function() {
32   chrome.test.getConfig(function(config) {
33     var guestURL = 'http://localhost:' + config.testServer.port +
34         '/extensions/platform_apps/ad_view/ad_network_site/testsdk.html';
35     runTests(guestURL);
36   });
37 }