Upstream version 5.34.98.0
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / platform_apps / ad_view / onloadcommit_ack / 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 page loaded inside an <adview> has the ability to
6 // 1) receive "message" events from the application, and 2) use
7 // "window.postMessage" to post back a message to the application.
8
9 function runTests(guestURL) {
10   chrome.test.runTests([
11     function test() {
12       var adview = document.getElementsByTagName("adview")[0];
13
14       adview.addEventListener("loadcommit", function() {
15         adview.contentWindow.postMessage({
16           message: "onloadcommit",
17           data: "data"
18         }, "*");
19       });
20
21       window.addEventListener("message", function(event) {
22         if (event.data.message == "onloadcommit-ack") {
23           console.log("onloadcommit-ack message received.");
24           chrome.test.succeed();
25         }
26       });
27
28       adview.setAttribute("src", guestURL);
29     }
30   ]);
31 }
32
33 window.onload = function() {
34   chrome.test.getConfig(function(config) {
35     var guestURL = 'http://localhost:' + config.testServer.port +
36         '/extensions/platform_apps/ad_view/ad_network_site/testsdk.html';
37     runTests(guestURL);
38   });
39 }