Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Side by Side Diff: chrome/test/data/extensions/api_test/downloads/test.js

Issue 9460010: test http auth-basic handling and implement headers.binaryValue for downloads.download() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fail/succeed Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // downloads api test 5 // downloads api test
6 // browser_tests.exe --gtest_filter=DownloadsApiTest.Downloads 6 // browser_tests.exe --gtest_filter=DownloadsApiTest.Downloads
7 7
8 var downloads = chrome.experimental.downloads; 8 var downloads = chrome.experimental.downloads;
9 9
10 chrome.test.getConfig(function(testConfig) { 10 chrome.test.getConfig(function(testConfig) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 // This URL should only work with the POST method and a request body 49 // This URL should only work with the POST method and a request body
50 // containing 'BODY'. 50 // containing 'BODY'.
51 var POST_URL = getURL('files/post/downloads/a_zip_file.zip?' + 51 var POST_URL = getURL('files/post/downloads/a_zip_file.zip?' +
52 'expected_body=BODY'); 52 'expected_body=BODY');
53 53
54 // This URL should only work with headers 'Foo: bar' and 'Qx: yo'. 54 // This URL should only work with headers 'Foo: bar' and 'Qx: yo'.
55 var HEADERS_URL = getURL('files/downloads/a_zip_file.zip?' + 55 var HEADERS_URL = getURL('files/downloads/a_zip_file.zip?' +
56 'expected_headers=Foo:bar&expected_headers=Qx:yo'); 56 'expected_headers=Foo:bar&expected_headers=Qx:yo');
57 57
58 // A simple handler that requires http auth basic.
59 var AUTH_BASIC_URL = getURL('auth-basic');
60
61 // This is just base64 of 'username:secret'.
62 var AUTHORIZATION = 'dXNlcm5hbWU6c2VjcmV0';
63
58 chrome.test.runTests([ 64 chrome.test.runTests([
59 // TODO(benjhayden): Test onErased using remove(). 65 // TODO(benjhayden): Test onErased using remove().
60 66
61 // TODO(benjhayden): Sub-directories depend on http://crbug.com/109443 67 // TODO(benjhayden): Sub-directories depend on http://crbug.com/109443
62 // TODO(benjhayden): Windows slashes. 68 // TODO(benjhayden): Windows slashes.
63 // function downloadSubDirectoryFilename() { 69 // function downloadSubDirectoryFilename() {
64 // var downloadId = getNextId(); 70 // var downloadId = getNextId();
65 // var callbackCompleted = chrome.test.callbackAdded(); 71 // var callbackCompleted = chrome.test.callbackAdded();
66 // function myListener(delta) { 72 // function myListener(delta) {
67 // if ((delta.id != downloadId) || 73 // if ((delta.id != downloadId) ||
68 // !delta.filename || 74 // !delta.filename ||
69 // (delta.filename.new.indexOf('/foo/slow') == -1)) 75 // (delta.filename.new.indexOf('/foo/slow') == -1))
70 // return; 76 // return;
71 // downloads.onChanged.removeListener(myListener); 77 // downloads.onChanged.removeListener(myListener);
72 // callbackCompleted(); 78 // callbackCompleted();
73 // } 79 // }
74 // downloads.onChanged.addListener(myListener); 80 // downloads.onChanged.addListener(myListener);
75 // downloads.download( 81 // downloads.download(
76 // {'url': SAFE_FAST_URL, 'filename': 'foo/slow'}, 82 // {'url': SAFE_FAST_URL, 'filename': 'foo/slow'},
77 // chrome.test.callback(function(id) { 83 // chrome.test.callback(function(id) {
78 // chrome.test.assertEq(downloadId, id); 84 // chrome.test.assertEq(downloadId, id);
79 // })); 85 // }));
80 // }, 86 // },
81 87
88 function downloadAuthBasicFail() {
cbentzel 2012/02/24 22:36:07 What happens in this case? Do you see an auth prom
benjhayden 2012/02/27 14:09:55 Nope, no prompt. The test succeeds. It detects the
cbentzel 2012/02/28 20:23:22 I'm still not entirely sure why you wouldn't get a
benjhayden 2012/03/01 18:43:18 Done.
cbentzel 2012/03/01 22:16:26 Done meaning the hole in my brain has been resolve
benjhayden 2012/03/02 14:43:47 Done meaning I don't see anything that I need to d
89 var downloadId = getNextId();
90 console.log(downloadId);
cbentzel 2012/02/28 20:23:22 Remove console.log Or you could add a debugLog()
benjhayden 2012/03/01 18:43:18 Done. Also, this test is still DISABLED.
91
92 var changedCompleted = chrome.test.callbackAdded();
93 function changedListener(delta) {
94 console.log(delta.id);
95 // Ignore onChanged events for downloads besides our own, or events that
96 // signal any change besides completion.
97 if ((delta.id != downloadId) ||
98 !delta.state ||
99 (delta.state.new != downloads.STATE_COMPLETE))
100 return;
101 // TODO(benjhayden): Change COMPLETE to INTERRUPTED after
cbentzel 2012/02/28 20:23:22 This may be fixed - see the most recent CL on http
benjhayden 2012/03/01 18:43:18 Done.
102 // http://crbug.com/112342
103 console.log(downloadId);
104 downloads.search({id: downloadId},
105 chrome.test.callback(function(items) {
106 console.log(downloadId);
107 chrome.test.assertEq(1, items.length);
108 chrome.test.assertEq(downloadId, items[0].id);
109 chrome.test.assertEq(427, items[0].bytesReceived);
110 chrome.test.assertEq(0, items[0].totalBytes);
111 chrome.test.assertEq(0, items[0].fileSize);
112 }));
113 downloads.onChanged.removeListener(changedListener);
114 changedCompleted();
115 }
116 downloads.onChanged.addListener(changedListener);
117
118 downloads.download(
119 {'url': AUTH_BASIC_URL,
120 'filename': downloadId + '.txt'},
121 chrome.test.callback(function(id) {
122 console.log(downloadId);
123 chrome.test.assertEq(downloadId, id);
124 }));
125 },
126
127 function downloadAuthBasicSucceed() {
128 var downloadId = getNextId();
129 console.log(downloadId);
130
131 var changedCompleted = chrome.test.callbackAdded();
132 function changedListener(delta) {
133 console.log(delta.id);
134 // Ignore onChanged events for downloads besides our own, or events that
135 // signal any change besides completion.
136 if ((delta.id != downloadId) ||
137 !delta.state ||
138 (delta.state.new != downloads.STATE_COMPLETE))
139 return;
140 console.log(downloadId);
141 downloads.search({id: downloadId},
142 chrome.test.callback(function(items) {
143 console.log(downloadId);
144 chrome.test.assertEq(1, items.length);
145 chrome.test.assertEq(downloadId, items[0].id);
146 chrome.test.assertEq(443, items[0].bytesReceived);
147 }));
148 downloads.onChanged.removeListener(changedListener);
149 changedCompleted();
150 }
151 downloads.onChanged.addListener(changedListener);
152
153 downloads.download(
154 {'url': AUTH_BASIC_URL,
155 'headers': [{'name': 'Authorization',
156 'value': 'Basic ' + AUTHORIZATION}],
157 'filename': downloadId + '.txt'},
158 chrome.test.callback(function(id) {
159 console.log(downloadId);
160 chrome.test.assertEq(downloadId, id);
161 }));
162 },
163
82 function downloadSimple() { 164 function downloadSimple() {
83 // Test that we can begin a download. 165 // Test that we can begin a download.
84 var downloadId = getNextId(); 166 var downloadId = getNextId();
85 console.log(downloadId); 167 console.log(downloadId);
86 downloads.download( 168 downloads.download(
87 {'url': SAFE_FAST_URL}, 169 {'url': SAFE_FAST_URL},
88 chrome.test.callback(function(id) { 170 chrome.test.callback(function(id) {
89 chrome.test.assertEq(downloadId, id); 171 chrome.test.assertEq(downloadId, id);
90 })); 172 }));
91 }, 173 },
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 }, 742 },
661 743
662 function callNotifyPass() { 744 function callNotifyPass() {
663 chrome.test.notifyPass(); 745 chrome.test.notifyPass();
664 setTimeout(chrome.test.callback(function() { 746 setTimeout(chrome.test.callback(function() {
665 console.log(''); 747 console.log('');
666 }), 0); 748 }), 0);
667 } 749 }
668 ]); 750 ]);
669 }); 751 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698