- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / platform_apps / web_view / common / execute_code / bootstrap.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 config.IS_CHROME_TEST = true;
6 // No TestServer.
7 config.IS_JS_ONLY_GUEST = true;
8 config.TEST_DIR = 'execute_code';
9
10 var executeCodeTests = {};
11 var g_webview;
12
13 var run = function() {
14   var container = document.createElement('div');
15   container.id = 'webview-tag-container';
16   document.body.appendChild(container);
17
18   chrome.test.getConfig(function(chromeConfig) {
19     window.console.log('getConfig: ' + chromeConfig);
20     utils.setUp(chromeConfig, config);
21     var step = 1;
22     embedder.loadGuest(function(webview) {
23       g_webview = webview;
24       window.console.log('bootstrap got embedder.loadGuest');
25       chrome.test.runTests([
26         executeCodeTests.testInsertCSS
27       ]);
28     }, function(data) {
29       LOG('embedder.onPostMessageReceived, data[0] = ' + data[0]);
30       if (data[0] == 'style') {
31         var propertyName = data[1];
32         var value = data[2];
33
34         switch (step) {
35           case 1:
36             chrome.test.assertEq('background-color', propertyName);
37             chrome.test.assertEq('rgba(0, 0, 0, 0)', value);
38             testBackgroundColorAfterCSSInjection();
39             step = 2;
40             break;
41           case 2:
42             chrome.test.assertEq('background-color', propertyName);
43             chrome.test.assertEq('rgb(255, 0, 0)', value);
44             chrome.test.succeed();
45             break;
46           default:
47             break;
48         }
49         return true;
50       }
51       return false;
52     }, 'foobar');
53   });
54 };
55
56 var testBackgroundColorAfterCSSInjection = function() {
57   LOG('testBackgroundColorAfterCSSInjection');
58   g_webview.insertCSS({file: 'execute_code/guest.css'}, function (results) {
59     // Verify that the background color is now red after injecting
60     // the CSS file.
61     LOG('testBackgroundColorAfterCSSInjection second postMessage send');
62     g_webview.contentWindow.postMessage(
63         JSON.stringify(['get-style', 'background-color']), '*');
64   });
65 };
66
67 executeCodeTests.testInsertCSS = function testInsertCSS() {
68   // Test the background color before CSS injection. Verify that the background
69   // color is indeed white.
70   g_webview.contentWindow.postMessage(
71       JSON.stringify(['get-style', 'background-color']), '*');
72 };
73
74 // Run tests.
75 run();