Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / test / data / extensions / api_test / log_private / dump_logs / test.js
blob58d307fd7b321169321d778888c581409e6834d4
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.
5 chrome.test.getConfig(function(config) {
6   runAllTests('http://www.test.com:' + config.testServer.port);
7 });
9 function runAllTests(testServerUrl) {
10   chrome.test.runTests([
11     function dumpLogsTest() {
12       chrome.logPrivate.dumpLogs(function(fileEntry) {
13         if (!fileEntry.name.match(/\.tar\.gz$/g)) {
14           chrome.test.fail('Invalid file type: '+ fileEntry.name);
15           return;
16         }
18         fileEntry.file(function(file) {
19             var reader = new FileReader();
20             reader.onloadend = function(e) {
21               if (this.result.byteLength > 0)
22                 chrome.test.succeed();
23               else
24                 chrome.test.fail('Invalid log file content');
25             };
26             reader.readAsArrayBuffer(file);
27           },
28           function() {
29             chrome.test.fail('File reading error');
30           });
31       });
32     },
33     function captureNetworkEvents() {
34       chrome.logPrivate.onCapturedEvents.addListener(function(entries) {
35         for (var i = 0; i < entries.length; i++) {
36           // Find our XHR request from below:
37           if (entries[i].params && entries[i].params.url &&
38                   entries[i].params.url.match(/www\.test\.com/g)) {
39             chrome.logPrivate.stopEventRecorder('network', function() {
40               chrome.test.succeed();
41             });
42           }
43         }
44       });
45       chrome.logPrivate.startEventRecorder('network', 'capture', function() {
46         var req = new XMLHttpRequest();
47         req.onreadystatechange = function() {}
48         req.open('GET', testServerUrl, true);
49         req.send();
50       });
51   }
52   ]);