OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 /* | 5 /* |
6 This extension is a file intent handler and does the following during the test: | 6 This extension is a file intent handler and does the following during the test: |
7 | 7 |
8 1. It first registers content hander. | 8 1. It first registers content hander. |
9 2. When content handler callback is invoked, opens tab.html page and passes | 9 2. When content handler callback is invoked, opens tab.html page and passes |
10 file url via hash ref. | 10 file url via hash ref. |
(...skipping 25 matching lines...) Expand all Loading... |
36 break; | 36 break; |
37 case FileError.INVALID_STATE_ERR: | 37 case FileError.INVALID_STATE_ERR: |
38 msg = 'INVALID_STATE_ERR'; | 38 msg = 'INVALID_STATE_ERR'; |
39 break; | 39 break; |
40 default: | 40 default: |
41 msg = 'Unknown Error'; | 41 msg = 'Unknown Error'; |
42 break; | 42 break; |
43 }; | 43 }; |
44 } | 44 } |
45 | 45 |
46 chrome.extension.sendMessage(fileBrowserExtensionId, | 46 chrome.runtime.sendMessage(fileBrowserExtensionId, |
47 {fileContent: null, | 47 {fileContent: null, |
48 error: {message: "File handler error: " + msg}}, | 48 error: {message: "File handler error: " + msg}}, |
49 function(response) {}); | 49 function(response) {}); |
50 }; | 50 }; |
51 | 51 |
52 function onSuccess(text) { | 52 function onSuccess(text) { |
53 chrome.extension.sendMessage( | 53 chrome.runtime.sendMessage( |
54 fileBrowserExtensionId, | 54 fileBrowserExtensionId, |
55 {fileContent: text, error: null}, | 55 {fileContent: text, error: null}, |
56 function(response) {}); | 56 function(response) {}); |
57 }; | 57 }; |
58 | 58 |
59 function writeToFile(entry, text) { | 59 function writeToFile(entry, text) { |
60 console.log('create writer'); | 60 console.log('create writer'); |
61 entry.createWriter(function(writer) { | 61 entry.createWriter(function(writer) { |
62 writer.onerror = function(e) { | 62 writer.onerror = function(e) { |
63 errorCallback(writer.error); | 63 errorCallback(writer.error); |
64 }; | 64 }; |
65 writer.onwrite = onSuccess.bind(this, text); | 65 writer.onwrite = onSuccess.bind(this, text); |
66 | 66 |
67 var blob = new Blob([text + text], {type: 'text/plain'}); | 67 var blob = new Blob([text + text], {type: 'text/plain'}); |
68 writer.write(blob); | 68 writer.write(blob); |
69 }); | 69 }); |
70 }; | 70 }; |
71 | 71 |
72 function runFileSystemHandlerTest(entries) { | 72 function runFileSystemHandlerTest(entries) { |
73 if (!entries || entries.length != 1 || !entries[0]) { | 73 if (!entries || entries.length != 1 || !entries[0]) { |
74 chrome.extension.sendMessage( | 74 chrome.runtime.sendMessage( |
75 fileBrowserExtensionId, | 75 fileBrowserExtensionId, |
76 {fileContent: null, error: 'Invalid file entries.'}, | 76 {fileContent: null, error: 'Invalid file entries.'}, |
77 function(response) {}); | 77 function(response) {}); |
78 return; | 78 return; |
79 } | 79 } |
80 var entry = entries[0]; | 80 var entry = entries[0]; |
81 var reader = new FileReader(); | 81 var reader = new FileReader(); |
82 reader.onloadend = function(e) { | 82 reader.onloadend = function(e) { |
83 writeToFile(entry, reader.result); | 83 writeToFile(entry, reader.result); |
84 }; | 84 }; |
(...skipping 30 matching lines...) Expand all Loading... |
115 // This extension just initializes its chrome.fileBrowserHandler.onExecute | 115 // This extension just initializes its chrome.fileBrowserHandler.onExecute |
116 // event listener, the real testing is done when this extension's handler is | 116 // event listener, the real testing is done when this extension's handler is |
117 // invoked from filebrowser_component tests. This event will be raised from that | 117 // invoked from filebrowser_component tests. This event will be raised from that |
118 // component extension test and it simulates user action in the file browser. | 118 // component extension test and it simulates user action in the file browser. |
119 // tab.html part of this extension can run only after the component raises this | 119 // tab.html part of this extension can run only after the component raises this |
120 // event, since that operation sets the propery security context and creates | 120 // event, since that operation sets the propery security context and creates |
121 // event's payload with proper file Entry instances. tab.html will return | 121 // event's payload with proper file Entry instances. tab.html will return |
122 // results of its execution to filebrowser_component test through a | 122 // results of its execution to filebrowser_component test through a |
123 // cross-component message. | 123 // cross-component message. |
124 chrome.test.succeed(); | 124 chrome.test.succeed(); |
OLD | NEW |