Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / extension_options / embed_self / options.js
1 // Copyright 2014 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 script is opened inside a <extensionoptions> guest view.
6
7 // This adds a 'loaded' property to the window for the createGuestViewDOM and
8 // createGuestViewProgrammatic tests.
9 window.loaded = true;
10
11 // This sends a message back to the test page, which responds with which test
12 // case it is running. The options page then runs the appropriate code for the
13 // specified test case.
14 chrome.runtime.sendMessage('ready', function(command) {
15   switch (command) {
16     case 'canCommunicateWithGuest':
17       // To confirm that the guest view has been successfully created,
18       // {pass: true} is added to every extension Window and broadcasts a
19       // message to the extension using runtime.sendMessage().
20       chrome.extension.getViews().forEach(function(view) {
21         view.pass = true;
22       });
23       chrome.runtime.sendMessage('done');
24       break;
25
26     case 'guestCanAccessStorage':
27       // To test access to privileged APIs, the guest attempts to write to local
28       // storage. The guest relays the callbacks for storage.onChanged and
29       // storage.set to the test runner for verification.
30       chrome.storage.onChanged.addListener(function(change) {
31         chrome.runtime.sendMessage({
32           expected: 42,
33           actual: change.test.newValue,
34           description: 'onStorageChanged'
35         });
36       });
37
38       chrome.storage.local.set({'test': 42}, function() {
39         chrome.storage.local.get('test', function(storage) {
40           chrome.runtime.sendMessage({
41             expected: 42,
42             actual: storage.test,
43             description: 'onSetAndGet'
44           });
45         });
46       });
47
48       break;
49
50     case 'externalLinksOpenInNewTab':
51       var link = document.getElementById('link');
52       chrome.test.runWithUserGesture(function() {
53         link.click();
54         chrome.runtime.sendMessage('done');
55       }.bind(link));
56   }
57 });