- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / webnavigation / test_getFrame.js
1 // Copyright (c) 2012 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 var URL = chrome.extension.getURL("getFrame/a.html");
6 var URL_FRAMES = chrome.extension.getURL("getFrame/b.html");
7 var tabId = -1;
8 var processId = -1;
9
10 chrome.test.runTests([
11   function testGetFrame() {
12     chrome.tabs.create({"url": "about:blank"}, function(tab) {
13       tabId = tab.id;
14       var done = chrome.test.listenForever(
15         chrome.webNavigation.onCommitted,
16         function (details) {
17           if (details.tabId != tabId)
18             return;
19           if (details.url != URL)
20             return;
21           processId = details.processId;
22           chrome.webNavigation.getFrame(
23               {tabId: tabId, frameId: 0, processId: processId},
24               function(details) {
25             chrome.test.assertEq(
26                 {errorOccurred: false, url: URL, parentFrameId: -1},
27                 details);
28             done();
29           });
30       });
31       chrome.tabs.update(tabId, {url: URL});
32     });
33   },
34
35   function testGetInvalidFrame() {
36     chrome.webNavigation.getFrame(
37         {tabId: tabId, frameId: 1, processId: processId},
38       function (details) {
39         chrome.test.assertEq(null, details);
40         chrome.test.succeed();
41     });
42   },
43
44   function testGetAllFrames() {
45     chrome.webNavigation.getAllFrames(
46         {tabId: tabId},
47       function (details) {
48         chrome.test.assertEq(
49             [{errorOccurred: false,
50               frameId: 0,
51               parentFrameId: -1,
52               processId: processId,
53               url: URL}],
54              details);
55         chrome.test.succeed();
56     });
57   },
58
59   // Load an URL with a frame which is detached during load. getAllFrames should
60   // only return the remaining (main) frame.
61   function testFrameDetach() {
62     chrome.tabs.create({"url": "about:blank"}, function(tab) {
63       tabId = tab.id;
64       var done = chrome.test.listenForever(
65         chrome.webNavigation.onCommitted,
66         function (details) {
67           if (details.tabId != tabId)
68             return;
69           if (details.url != URL_FRAMES)
70             return;
71           processId = details.processId;
72           chrome.webNavigation.getAllFrames(
73               {tabId: tabId},
74             function (details) {
75               chrome.test.assertEq(
76                   [{errorOccurred: false,
77                     frameId: 0,
78                     parentFrameId: -1,
79                     processId: processId,
80                     url: URL_FRAMES}],
81                    details);
82               chrome.test.succeed();
83           });
84       });
85       chrome.tabs.update(tabId, {url: URL_FRAMES});
86     });
87   },
88
89 ]);