| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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 // API test for chrome.extension.savePage. | |
| 6 // browser_tests.exe --gtest_filter=ExtensionApiTest.SavePage | |
| 7 | |
| 8 const assertEq = chrome.test.assertEq; | |
| 9 const assertTrue = chrome.test.assertTrue; | |
| 10 | |
| 11 var testUrl = 'http://www.a.com:PORT' + | |
| 12 '/files/extensions/api_test/save_page/google.html'; | |
| 13 | |
| 14 function waitForCurrentTabLoaded(callback) { | |
| 15 chrome.tabs.getSelected(null, function(tab) { | |
| 16 if (tab.status == "complete" && tab.url == testUrl) { | |
| 17 callback(); | |
| 18 return; | |
| 19 } | |
| 20 window.setTimeout(function() { waitForCurrentTabLoaded(callback); }, 100); | |
| 21 }); | |
| 22 } | |
| 23 | |
| 24 chrome.test.getConfig(function(config) { | |
| 25 testUrl = testUrl.replace(/PORT/, config.testServer.port); | |
| 26 | |
| 27 chrome.test.runTests([ | |
| 28 function savePageAsMHTML() { | |
| 29 chrome.tabs.getSelected(null, function(tab) { | |
| 30 chrome.tabs.update(null, { "url": testUrl }); | |
| 31 waitForCurrentTabLoaded(function() { | |
| 32 chrome.experimental.savePage.saveAsMHTML({ "tabId": tab.id }, | |
| 33 function(data) { | |
| 34 assertEq(undefined, chrome.extension.lastError); | |
| 35 assertTrue(data != null); | |
| 36 // It should contain few KBs of data. | |
| 37 assertTrue(data.size > 100); | |
| 38 // Let's make sure it contains some well known strings. | |
| 39 var reader = new FileReader(); | |
| 40 reader.onload = function(e) { | |
| 41 var text = e.target.result; | |
| 42 assertTrue(text.indexOf(testUrl) != -1); | |
| 43 assertTrue(text.indexOf("logo.png") != -1); | |
| 44 // Run the GC so the blob is deleted. | |
| 45 window.setTimeout(function() { window.gc(); }); | |
| 46 window.setTimeout(function() { chrome.test.notifyPass(); }, 0); | |
| 47 }; | |
| 48 reader.readAsText(data); | |
| 49 }); | |
| 50 }); | |
| 51 }); | |
| 52 } | |
| 53 ]); | |
| 54 }); | |
| 55 | |
| OLD | NEW |