Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / ui / file_manager / image_loader / image_loader_client_unittest.js
blobce56ae29739531cc1a8dbeacea0729568a702894
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 'use strict';
7 var chrome = {
8 metricsPrivate: {
9 recordPercentage: function() {},
10 recordValue: function() {}
12 i18n: {
13 getMessage: function() {}
17 /**
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) {
27 var cacheUsed = true;
29 ImageLoaderClient.sendMessage_ = function(message, callback) {
30 cacheUsed = false;
31 if (callback)
32 callback({data: 'ImageData', width: 100, height: 100, status: 'success'});
35 return new Promise(function(fulfill) {
36 client.load(url, function() {
37 fulfill(cacheUsed);
38 }, options);
39 });
42 function testCache(callback) {
43 var client = new ImageLoaderClient();
44 reportPromise(
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});
51 }).
52 then(function(cacheUsed) {
53 assertTrue(cacheUsed);
54 }),
55 callback);
58 function testNoCache(callback) {
59 var client = new ImageLoaderClient();
60 reportPromise(
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});
67 }).
68 then(function(cacheUsed) {
69 assertFalse(cacheUsed);
70 }),
71 callback);
74 function testDataURLCache(callback) {
75 var client = new ImageLoaderClient();
76 reportPromise(
77 loadAndCheckCacheUsed(client, 'data:URI', {cache: true}).
78 then(function(cacheUsed) {
79 assertFalse(cacheUsed);
80 return loadAndCheckCacheUsed(client, 'data:URI', {cache: true});
81 }).
82 then(function(cacheUsed) {
83 assertFalse(cacheUsed);
84 }),
85 callback);