1 // Copyright 2015 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 getMetricName: function() {},
11 recordEnum: function() {},
12 recordInterval: function() {},
13 startInterval: function() {}
18 * Mock of ImageEncoder. Since some test changes the behavior of ImageEncoder,
19 * this is initialized in setUp().
27 DRIVE_DIRECTORY_LABEL
: '',
28 DOWNLOADS_DIRECTORY_LABEL
: ''
33 encodeMetadata: function() {},
34 getBlob: function() {}
39 * Returns a mock of metadata model.
41 * @return {!MetadataModel}
43 function getMockMetadataModel() {
45 get: function(entries
, names
) {
46 return Promise
.resolve([
50 notifyEntriesChanged: function() {
56 * Tests for GalleryItem#saveToFile.
58 function testSaveToFile(callback
) {
59 var fileSystem
= new MockFileSystem('volumeId');
60 fileSystem
.populate(['/test.jpg']);
61 var entry
= fileSystem
.entries
['/test.jpg'];
62 entry
.createWriter = function(callback
) {
65 Promise
.resolve().then(function() {
69 truncate: function() {
74 var entryChanged
= false;
75 var metadataModel
= getMockMetadataModel();
76 metadataModel
.notifyEntriesChanged = function() {
80 var item
= new Gallery
.Item(
86 assertEquals(100, item
.getMetadataItem().size
);
87 assertFalse(entryChanged
);
89 new Promise(item
.saveToFile
.bind(
91 {getLocationInfo: function() { return {}; }},
93 /* fallbackDir */ null,
95 document
.createElement('canvas'))).then(function() {
96 assertEquals(200, item
.getMetadataItem().size
);
97 assertTrue(entryChanged
);
102 * Tests for GalleryItem#saveToFile. In this test case, fileWriter.write fails
105 function testSaveToFileWriteFailCase(callback
) {
106 var fileSystem
= new MockFileSystem('volumeId');
107 fileSystem
.populate(['/test.jpg']);
108 var entry
= fileSystem
.entries
['/test.jpg'];
110 entry
.createWriter = function(callback
) {
113 Promise
.resolve().then(function() {
114 this.onerror(new Error());
117 truncate: function() {
118 Promise
.resolve().then(function() {
125 var item
= new Gallery
.Item(
130 /* original */ true);
132 new Promise(item
.saveToFile
.bind(
134 {getLocationInfo: function() { return {}; }},
135 getMockMetadataModel(),
136 /* fallbackDir */ null,
137 /* overwrite */ true,
138 document
.createElement('canvas'))).then(function(result
) {
144 * Tests for GalleryItem#saveToFile. In this test case, ImageEncoder.getBlob
145 * fails with an error. This test case confirms that no write operation runs
146 * when it fails to get a blob of new image.
148 function testSaveToFileGetBlobFailCase(callback
) {
149 ImageEncoder
.getBlob = function() {
153 var fileSystem
= new MockFileSystem('volumeId');
154 fileSystem
.populate(['/test.jpg']);
155 var entry
= fileSystem
.entries
['/test.jpg'];
157 var writeOperationRun
= false;
158 entry
.createWriter = function(callback
) {
161 Promise
.resolve().then(function() {
162 writeOperationRun
= true;
166 truncate: function() {
167 Promise
.resolve().then(function() {
168 writeOperationRun
= true;
175 var item
= new Gallery
.Item(
180 /* original */ true);
182 new Promise(item
.saveToFile
.bind(
184 {getLocationInfo: function() { return {}; }},
185 getMockMetadataModel(),
186 /* fallbackDir */ null,
187 /* overwrite */ true,
188 document
.createElement('canvas'))).then(function(result
) {
190 assertFalse(writeOperationRun
);