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.
9 recordPercentage: function() {},
10 recordValue: function() {}
13 getMessage: function() {}
18 * Lets the client to load URL and returns the local cache (not caches in the
19 * image loader extension) is used or not.
21 * @param {ImageLoaderClient} client
22 * @param {string} url URL
23 * @param {Object} options load options.
24 * @return {Promise<boolean>} True if the local cache is used.
26 function loadAndCheckCacheUsed(client
, url
, options
) {
29 ImageLoaderClient
.sendMessage_ = function(message
, callback
) {
32 callback({data
: 'ImageData', width
: 100, height
: 100, status
: 'success'});
35 return new Promise(function(fulfill
) {
36 client
.load(url
, function() {
42 function testCache(callback
) {
43 var client
= new ImageLoaderClient();
45 loadAndCheckCacheUsed(
46 client
, 'http://example.com/image.jpg', {cache
: true}).
47 then(function(cacheUsed
) {
48 assertFalse(cacheUsed
);
49 return loadAndCheckCacheUsed(
50 client
, 'http://example.com/image.jpg', {cache
: true});
52 then(function(cacheUsed
) {
53 assertTrue(cacheUsed
);
58 function testNoCache(callback
) {
59 var client
= new ImageLoaderClient();
61 loadAndCheckCacheUsed(
62 client
, 'http://example.com/image.jpg', {cache
: false}).
63 then(function(cacheUsed
) {
64 assertFalse(cacheUsed
);
65 return loadAndCheckCacheUsed(
66 client
, 'http://example.com/image.jpg', {cache
: false});
68 then(function(cacheUsed
) {
69 assertFalse(cacheUsed
);
74 function testDataURLCache(callback
) {
75 var client
= new ImageLoaderClient();
77 loadAndCheckCacheUsed(client
, 'data:URI', {cache
: true}).
78 then(function(cacheUsed
) {
79 assertFalse(cacheUsed
);
80 return loadAndCheckCacheUsed(client
, 'data:URI', {cache
: true});
82 then(function(cacheUsed
) {
83 assertFalse(cacheUsed
);