OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 var cwsContainerMock = {}; | 5 var cwsContainerMock = {}; |
6 (function() { | 6 (function() { |
7 // This ID will be checked in the test. | 7 // This ID will be checked in the test. |
8 var DUMMY_ITEM_ID = 'DUMMY_ITEM_ID_FOR_TEST'; | 8 var DUMMY_ITEM_ID = 'DUMMY_ITEM_ID_FOR_TEST'; |
9 | 9 |
10 var origin = null; | 10 var origin = null; |
11 var data = null; | 11 var data = null; |
12 var source = null; | 12 var source = null; |
13 | 13 |
14 cwsContainerMock.onMessage = function (message) { | 14 cwsContainerMock.onMessage = function (message) { |
15 data = message.data; | 15 data = message.data; |
16 source = message.source; | 16 source = message.source; |
17 origin = message.origin; | 17 origin = message.origin; |
18 | 18 |
19 switch (data['message']) { | 19 switch (data['message']) { |
20 case 'initialize': | 20 case 'initialize': |
21 cwsContainerMock.onInitialize(source); | 21 cwsContainerMock.onInitialize(); |
| 22 break; |
| 23 case 'install_success': |
| 24 cwsContainerMock.onInstallSuccess(); |
22 break; | 25 break; |
23 }; | 26 }; |
24 } | 27 } |
25 | 28 |
26 cwsContainerMock.onInitialize = function() { | 29 cwsContainerMock.onInitialize = function() { |
27 if (source && origin) | 30 if (source && origin) |
28 source.postMessage({message: 'widget_loaded'}, origin); | 31 source.postMessage({message: 'widget_loaded'}, origin); |
29 }; | 32 }; |
30 | 33 |
| 34 cwsContainerMock.onInstallSuccess = function() { |
| 35 if (source && origin) |
| 36 source.postMessage({ |
| 37 message: 'after_install', |
| 38 item_id: DUMMY_ITEM_ID |
| 39 }, origin); |
| 40 }; |
| 41 |
31 cwsContainerMock.onInstallButton = function() { | 42 cwsContainerMock.onInstallButton = function() { |
32 if (source && origin) { | 43 if (source && origin) { |
33 source.postMessage( | 44 source.postMessage( |
34 {message: 'before_install', item_id:DUMMY_ITEM_ID}, origin); | 45 {message: 'before_install', item_id:DUMMY_ITEM_ID}, origin); |
35 } | 46 } |
36 }; | 47 }; |
37 | 48 |
38 })(); | 49 })(); |
39 | 50 |
40 function onInstallButton() { | 51 function onInstallButton() { |
41 cwsContainerMock.onInstallButton(); | 52 cwsContainerMock.onInstallButton(); |
42 }; | 53 }; |
43 | 54 |
44 window.addEventListener('message', cwsContainerMock.onMessage); | 55 window.addEventListener('message', cwsContainerMock.onMessage); |
OLD | NEW |