- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / content_scripts / all_frames / test.js
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 // We load a page that has one iframe
6 // So we should receive two "all_frames" messages, and one "top_frame_only"
7 // messages.
8
9 var num_all_frames_messages = 0;
10 var num_top_frame_only_messages = 0;
11
12 chrome.test.runTests([
13   // Tests receiving a request from a content script and responding.
14   function onRequest() {
15     chrome.extension.onRequest.addListener(
16       function(request, sender, sendResponse) {
17         if (request == "all_frames") {
18           num_all_frames_messages++;
19         } else if (request == "top_frame_only") {
20           num_top_frame_only_messages++;
21         } else {
22           chrome.test.fail("Unexpected request: " + JSON.stringify(request));
23         }
24
25         if (num_all_frames_messages == 2 && num_top_frame_only_messages == 1) {
26           chrome.test.succeed();
27         }
28       }
29     );
30   }
31 ]);
32
33 chrome.test.getConfig(function(config) {
34   chrome.test.log("Creating tab...");
35
36   var test_url =
37       "http://localhost:PORT/extensions/test_file_with_iframe.html"
38           .replace(/PORT/, config.testServer.port);
39
40   chrome.tabs.create({ url: test_url });
41 });
42