forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This test case is not a case to check the bug is fixed but to find a regression in the following fix. BUG=437142 TEST=out/Release/browser_tests --gtest_filter=*GalleryJsTest* Review URL: https://codereview.chromium.org/767663002 Cr-Commit-Position: refs/heads/master@{#307383}
- Loading branch information
yawano
authored and
Commit bot
committed
Dec 9, 2014
1 parent
05624cf
commit c41b65b
Showing
6 changed files
with
153 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include <vector> | ||
|
||
#include "chrome/browser/ui/browser.h" | ||
#include "chrome/browser/ui/tabs/tab_strip_model.h" | ||
#include "chrome/test/base/in_process_browser_test.h" | ||
#include "chrome/test/base/ui_test_utils.h" | ||
#include "content/public/browser/web_contents.h" | ||
#include "content/public/test/browser_test_utils.h" | ||
|
||
class GalleryJsTest : public InProcessBrowserTest { | ||
public: | ||
// Runs all test functions in |file|, waiting for them to complete. | ||
void RunTest(const base::FilePath& file) { | ||
const GURL url = ui_test_utils::GetTestUrl( | ||
base::FilePath(FILE_PATH_LITERAL("gallery/unit_tests")), file); | ||
ui_test_utils::NavigateToURL(browser(), url); | ||
|
||
content::WebContents* const web_contents = | ||
browser()->tab_strip_model()->GetActiveWebContents(); | ||
ASSERT_TRUE(web_contents); | ||
|
||
const std::vector<int> empty_libraries; | ||
EXPECT_TRUE(ExecuteWebUIResourceTest(web_contents, empty_libraries)); | ||
} | ||
}; | ||
|
||
IN_PROC_BROWSER_TEST_F(GalleryJsTest, ExifEncoderTest) { | ||
RunTest(base::FilePath( | ||
FILE_PATH_LITERAL("exif_encoder_unittest.html"))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
chrome/test/data/gallery/unit_tests/exif_encoder_unittest.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!DOCTYPE html> | ||
<!-- Copyright 2014 The Chromium Authors. All rights reserved. | ||
-- Use of this source code is governed by a BSD-style license that can be | ||
-- found in the LICENSE file. | ||
--> | ||
<html> | ||
<body> | ||
|
||
<script type="text/javascript"> | ||
// importScripts is used in metadata_dispatcher.js which is designed to work inside SharedWorker. | ||
function importScripts(arg1) {} | ||
</script> | ||
<script src="../../../../../ui/webui/resources/js/assert.js"></script> | ||
|
||
<script src="../../../../../ui/file_manager/file_manager/foreground/js/metadata/metadata_cache.js"></script> | ||
<script src="../../../../../ui/file_manager/file_manager/foreground/js/metadata/byte_reader.js"></script> | ||
<script src="../../../../../ui/file_manager/file_manager/foreground/js/metadata/metadata_parser.js"></script> | ||
<script src="../../../../../ui/file_manager/file_manager/foreground/js/metadata/metadata_dispatcher.js"></script> | ||
<script src="../../../../../ui/file_manager/file_manager/foreground/js/metadata/exif_parser.js"></script> | ||
|
||
<script src="../../../../../ui/file_manager/gallery/js/image_editor/image_encoder.js"></script> | ||
<script src="../../../../../ui/file_manager/gallery/js/image_editor/exif_encoder.js"></script> | ||
|
||
<script src="exif_encoder_unittest.js"></script> | ||
|
||
</body> | ||
</html> |
89 changes: 89 additions & 0 deletions
89
chrome/test/data/gallery/unit_tests/exif_encoder_unittest.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
'use strict'; | ||
|
||
/** | ||
* Creates a sample canvas. | ||
* @return {HTMLCanvasElement} | ||
*/ | ||
function getSampleCanvas() { | ||
var canvas = document.createElement('canvas'); | ||
canvas.width = 1920; | ||
canvas.height = 1080; | ||
|
||
var ctx = canvas.getContext('2d'); | ||
ctx.fillStyle = '#000000'; | ||
for (var i = 0; i < 10; i++) { | ||
ctx.fillRect(i * 30, i * 30, 20, 20); | ||
} | ||
|
||
return canvas; | ||
} | ||
|
||
/** | ||
* Test case for ordinal exif encoding and decoding. | ||
*/ | ||
function testExifEncodeAndDecode() { | ||
var canvas = getSampleCanvas(); | ||
var data = canvas.toDataURL('image/jpeg'); | ||
|
||
var metadata = { | ||
media: { | ||
mimeType: 'image/jpeg', | ||
ifd: { | ||
image: { | ||
// Manufacture | ||
271: { | ||
id: 0x10f, | ||
format: 2, | ||
componentCount: 12, | ||
value: 'Manufacture' | ||
}, | ||
// Device model | ||
272: { | ||
id: 0x110, | ||
format: 2, | ||
componentCount: 12, | ||
value: 'DeviceModel' | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
var encoder = ImageEncoder.encodeMetadata(metadata, canvas); | ||
|
||
// Assert that ExifEncoder is returned. | ||
assertTrue(encoder instanceof ExifEncoder); | ||
|
||
var encodedResult = encoder.encode(); | ||
|
||
// Decode encoded exif data. | ||
var exifParser = new ExifParser(this); | ||
|
||
// Redirect .log and .vlog to console.log for debugging. | ||
exifParser.log = function(arg) { console.log(arg); }; | ||
exifParser.vlog = function(arg) { console.log(arg); }; | ||
|
||
var parsedMetadata = {}; | ||
var byteReader = new ByteReader(encodedResult); | ||
byteReader.readString(2 + 2); // Skip marker and size. | ||
exifParser.parseExifSection(parsedMetadata, encodedResult, byteReader); | ||
|
||
// Check ifd.image. | ||
assertEquals(1, parsedMetadata.ifd.image[0x112].value); // Orientation | ||
|
||
// Check ifd.exif. | ||
assertEquals(1920, parsedMetadata.ifd.exif[0xA002].value); // PixelXDimension | ||
assertEquals(1080, parsedMetadata.ifd.exif[0xA003].value); // PixelYDimension | ||
|
||
// TODO(yawano) Change exif_encoder to preserve these fields. | ||
// These fileds are not encoded. | ||
assertEquals(undefined, parsedMetadata.ifd.image[0x10F]); // Manufacture | ||
assertEquals(undefined, parsedMetadata.ifd.image[0x110]); // Device model | ||
|
||
// Thumbnail image | ||
assert(parsedMetadata.thumbnailTransform); | ||
assert(parsedMetadata.thumbnailURL); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters