| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import tempfile |
| 6 import os |
| 5 import unittest | 7 import unittest |
| 6 import os | |
| 7 | 8 |
| 8 from telemetry.core import bitmap | 9 from telemetry.core import bitmap |
| 9 from telemetry.core import util | 10 from telemetry.core import util |
| 10 | 11 |
| 11 | 12 |
| 12 # This is a simple base64 encoded 2x2 PNG which contains, in order, a single | 13 # This is a simple base64 encoded 2x2 PNG which contains, in order, a single |
| 13 # Red, Yellow, Blue, and Green pixel. | 14 # Red, Yellow, Blue, and Green pixel. |
| 14 test_png = """ | 15 test_png = """ |
| 15 iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91 | 16 iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91 |
| 16 JpzAAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACx | 17 JpzAAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACx |
| (...skipping 11 matching lines...) Expand all Loading... |
| 28 bmp = bitmap.Bitmap.FromBase64Png(test_png) | 29 bmp = bitmap.Bitmap.FromBase64Png(test_png) |
| 29 | 30 |
| 30 self.assertEquals(2, bmp.width) | 31 self.assertEquals(2, bmp.width) |
| 31 self.assertEquals(2, bmp.height) | 32 self.assertEquals(2, bmp.height) |
| 32 | 33 |
| 33 bmp.GetPixelColor(0, 0).AssertIsRGB(255, 0, 0) | 34 bmp.GetPixelColor(0, 0).AssertIsRGB(255, 0, 0) |
| 34 bmp.GetPixelColor(1, 1).AssertIsRGB(0, 255, 0) | 35 bmp.GetPixelColor(1, 1).AssertIsRGB(0, 255, 0) |
| 35 bmp.GetPixelColor(0, 1).AssertIsRGB(0, 0, 255) | 36 bmp.GetPixelColor(0, 1).AssertIsRGB(0, 0, 255) |
| 36 bmp.GetPixelColor(1, 0).AssertIsRGB(255, 255, 0) | 37 bmp.GetPixelColor(1, 0).AssertIsRGB(255, 255, 0) |
| 37 | 38 |
| 38 def testReadFromPnfFile(self): | 39 def testReadFromPngFile(self): |
| 39 file_bmp = bitmap.Bitmap.FromPngFile(test_png_path) | 40 file_bmp = bitmap.Bitmap.FromPngFile(test_png_path) |
| 40 | 41 |
| 41 self.assertEquals(2, file_bmp.width) | 42 self.assertEquals(2, file_bmp.width) |
| 42 self.assertEquals(2, file_bmp.height) | 43 self.assertEquals(2, file_bmp.height) |
| 43 | 44 |
| 44 file_bmp.GetPixelColor(0, 0).AssertIsRGB(255, 0, 0) | 45 file_bmp.GetPixelColor(0, 0).AssertIsRGB(255, 0, 0) |
| 45 file_bmp.GetPixelColor(1, 1).AssertIsRGB(0, 255, 0) | 46 file_bmp.GetPixelColor(1, 1).AssertIsRGB(0, 255, 0) |
| 46 file_bmp.GetPixelColor(0, 1).AssertIsRGB(0, 0, 255) | 47 file_bmp.GetPixelColor(0, 1).AssertIsRGB(0, 0, 255) |
| 47 file_bmp.GetPixelColor(1, 0).AssertIsRGB(255, 255, 0) | 48 file_bmp.GetPixelColor(1, 0).AssertIsRGB(255, 255, 0) |
| 48 | 49 |
| 50 def testWritePngFile(self): |
| 51 orig = bitmap.Bitmap.FromPngFile(test_png_path) |
| 52 temp_file = tempfile.NamedTemporaryFile().name |
| 53 orig.WritePngFile(temp_file) |
| 54 new_file = bitmap.Bitmap.FromPngFile(temp_file) |
| 55 self.assertTrue(orig.IsEqual(new_file)) |
| 56 |
| 49 def testIsEqual(self): | 57 def testIsEqual(self): |
| 50 bmp = bitmap.Bitmap.FromBase64Png(test_png) | 58 bmp = bitmap.Bitmap.FromBase64Png(test_png) |
| 51 file_bmp = bitmap.Bitmap.FromPngFile(test_png_path) | 59 file_bmp = bitmap.Bitmap.FromPngFile(test_png_path) |
| 52 self.assertTrue(bmp.IsEqual(file_bmp)) | 60 self.assertTrue(bmp.IsEqual(file_bmp)) |
| 53 | 61 |
| 54 def testDiff(self): | 62 def testDiff(self): |
| 55 file_bmp = bitmap.Bitmap.FromPngFile(test_png_path) | 63 file_bmp = bitmap.Bitmap.FromPngFile(test_png_path) |
| 56 file_bmp_2 = bitmap.Bitmap.FromPngFile(test_png_2_path) | 64 file_bmp_2 = bitmap.Bitmap.FromPngFile(test_png_2_path) |
| 57 | 65 |
| 58 diff_bmp = file_bmp.Diff(file_bmp) | 66 diff_bmp = file_bmp.Diff(file_bmp) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 73 diff_bmp.GetPixelColor(0, 0).AssertIsRGB(0, 255, 255) | 81 diff_bmp.GetPixelColor(0, 0).AssertIsRGB(0, 255, 255) |
| 74 diff_bmp.GetPixelColor(1, 1).AssertIsRGB(255, 0, 255) | 82 diff_bmp.GetPixelColor(1, 1).AssertIsRGB(255, 0, 255) |
| 75 diff_bmp.GetPixelColor(0, 1).AssertIsRGB(255, 255, 0) | 83 diff_bmp.GetPixelColor(0, 1).AssertIsRGB(255, 255, 0) |
| 76 diff_bmp.GetPixelColor(1, 0).AssertIsRGB(0, 0, 255) | 84 diff_bmp.GetPixelColor(1, 0).AssertIsRGB(0, 0, 255) |
| 77 | 85 |
| 78 diff_bmp.GetPixelColor(0, 2).AssertIsRGB(255, 255, 255) | 86 diff_bmp.GetPixelColor(0, 2).AssertIsRGB(255, 255, 255) |
| 79 diff_bmp.GetPixelColor(1, 2).AssertIsRGB(255, 255, 255) | 87 diff_bmp.GetPixelColor(1, 2).AssertIsRGB(255, 255, 255) |
| 80 diff_bmp.GetPixelColor(2, 0).AssertIsRGB(255, 255, 255) | 88 diff_bmp.GetPixelColor(2, 0).AssertIsRGB(255, 255, 255) |
| 81 diff_bmp.GetPixelColor(2, 1).AssertIsRGB(255, 255, 255) | 89 diff_bmp.GetPixelColor(2, 1).AssertIsRGB(255, 255, 255) |
| 82 diff_bmp.GetPixelColor(2, 2).AssertIsRGB(255, 255, 255) | 90 diff_bmp.GetPixelColor(2, 2).AssertIsRGB(255, 255, 255) |
| OLD | NEW |