- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / icons / extension_with_permission / index.js
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
3 // found in the LICENSE file.
4
5 var TEST_CASES = [
6   // Tests loading a standard 128px icon.
7   {
8     url: 'chrome://extension-icon/gbmgkahjioeacddebbnengilkgbkhodg/128/0',
9     expectedSize: 128
10   },
11   // Tests loading a standard 48px icon with a MATCH_SMALLER.
12   // This should not be resized to 48px.
13   {
14     url: 'chrome://extension-icon/gbmgkahjioeacddebbnengilkgbkhodg/48/2',
15     expectedSize: 32
16   },
17   // Tests loading a standard 32px icon, grayscale. We assume that we actually
18   // got a grayscale image back here.
19   {
20     url: 'chrome://extension-icon/gbmgkahjioeacddebbnengilkgbkhodg/' +
21         '32/1?grayscale=true',
22     expectedSize: 32
23   },
24   // Tests loading a 16px by resizing the 32px version (MATCH_BIGGER).
25   // This should be resized to 16px.
26   {
27     url: 'chrome://extension-icon/gbmgkahjioeacddebbnengilkgbkhodg/16/1',
28     expectedSize: 16
29   }
30 ];
31
32 var loadedImageCount = 0;
33
34 TEST_CASES.forEach(function(testCase) {
35   var img = document.createElement('img');
36   img.onload = function() {
37     if (img.naturalWidth != testCase.expectedSize ||
38         img.naturalHeight != testCase.expectedSize) {
39       document.title = 'Incorrect size on ' + testCase.url +
40           ' Expected: ' + testCase.expectedSize + 'x' + testCase.expectedSize +
41           ' Actual: ' + img.naturalWidth + 'x' + img.naturalHeight;
42       return;
43     }
44
45     if (++loadedImageCount == TEST_CASES.length) {
46       document.title = 'Loaded';
47     }
48   };
49   img.onerror = function() {
50     // We failed to load an image that should have loaded.
51     document.title = 'Couldn\'t load ' + testCase.url;
52   };
53   img.src = testCase.url;
54   document.body.appendChild(img);
55 });