Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(368)

Side by Side Diff: chrome/test/automation/automation_proxy_uitest.cc

Issue 8416024: Re-land 107645 with static initializers removed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove static initializers Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include <string> 5 #include <string>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/i18n/rtl.h" 11 #include "base/i18n/rtl.h"
12 #include "base/json/json_value_serializer.h" 12 #include "base/json/json_value_serializer.h"
13 #include "base/md5.h"
13 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
14 #include "base/scoped_temp_dir.h" 15 #include "base/scoped_temp_dir.h"
15 #include "base/string_util.h" 16 #include "base/string_util.h"
16 #include "base/stringprintf.h" 17 #include "base/stringprintf.h"
17 #include "base/sys_info.h" 18 #include "base/sys_info.h"
18 #include "base/test/test_timeouts.h" 19 #include "base/test/test_timeouts.h"
19 #include "base/utf_string_conversions.h" 20 #include "base/utf_string_conversions.h"
20 #include "build/build_config.h" 21 #include "build/build_config.h"
21 #include "chrome/app/chrome_command_ids.h" 22 #include "chrome/app/chrome_command_ids.h"
22 #include "chrome/browser/ui/view_ids.h" 23 #include "chrome/browser/ui/view_ids.h"
(...skipping 1499 matching lines...) Expand 10 before | Expand all | Expand 10 after
1522 AutomationProxySnapshotTest() { 1523 AutomationProxySnapshotTest() {
1523 dom_automation_enabled_ = true; 1524 dom_automation_enabled_ = true;
1524 if (!snapshot_dir_.CreateUniqueTempDir()) 1525 if (!snapshot_dir_.CreateUniqueTempDir())
1525 ADD_FAILURE() << "Unable to create temporary directory"; 1526 ADD_FAILURE() << "Unable to create temporary directory";
1526 else 1527 else
1527 snapshot_path_ = snapshot_dir_.path().AppendASCII("snapshot.png"); 1528 snapshot_path_ = snapshot_dir_.path().AppendASCII("snapshot.png");
1528 } 1529 }
1529 1530
1530 // Asserts that the given png file can be read and decoded into the given 1531 // Asserts that the given png file can be read and decoded into the given
1531 // bitmap. 1532 // bitmap.
1532 void AssertReadPNG(const FilePath& filename, SkBitmap* bitmap) { 1533 void AssertReadPNG(const FilePath& filename, std::string* data) {
1533 DCHECK(bitmap);
1534 ASSERT_TRUE(file_util::PathExists(filename)); 1534 ASSERT_TRUE(file_util::PathExists(filename));
1535 1535
1536 int64 size64; 1536 int64 size64;
1537 ASSERT_TRUE(file_util::GetFileSize(filename, &size64)); 1537 ASSERT_TRUE(file_util::GetFileSize(filename, &size64));
1538 // Check that the file is not too big to read in (less than 100 MB). 1538 // Check that the file is not too big to read in (less than 100 MB).
1539 ASSERT_LT(size64, 1024 * 1024 * 100); 1539 ASSERT_LT(size64, 1024 * 1024 * 100);
1540 1540
1541 // Read and decode image. 1541 // Read and decode image.
1542 int size = static_cast<int>(size64); 1542 int size = static_cast<int>(size64);
1543 scoped_array<char> data(new char[size]); 1543 data->resize(size);
1544 int bytes_read = file_util::ReadFile(filename, &data[0], size); 1544 int bytes_read = file_util::ReadFile(filename, &(*data)[0], size);
1545 ASSERT_EQ(size, bytes_read); 1545 ASSERT_EQ(size, bytes_read);
1546 ASSERT_TRUE(gfx::PNGCodec::Decode(
1547 reinterpret_cast<unsigned char*>(&data[0]),
1548 bytes_read,
1549 bitmap));
1550 } 1546 }
1551 1547
1552 // Returns the file path for the directory for these tests appended with 1548 // Returns the file path for the directory for these tests appended with
1553 // the given relative path. 1549 // the given relative path.
1554 FilePath GetTestFilePath(const std::string& relative_path) { 1550 FilePath GetTestFilePath(const std::string& relative_path) {
1555 FilePath filename(test_data_directory_); 1551 FilePath filename(test_data_directory_);
1556 return filename.AppendASCII("automation_proxy_snapshot") 1552 return filename.AppendASCII("automation_proxy_snapshot")
1557 .AppendASCII(relative_path); 1553 .AppendASCII(relative_path);
1558 } 1554 }
1559 1555
1560 GURL GetTestUrl(const std::string& relative_path, const std::string& query) { 1556 GURL GetTestUrl(const std::string& relative_path, const std::string& query) {
1561 FilePath file_path = GetTestFilePath(relative_path); 1557 FilePath file_path = GetTestFilePath(relative_path);
1562 return ui_test_utils::GetFileUrlWithQuery(file_path, query); 1558 return ui_test_utils::GetFileUrlWithQuery(file_path, query);
1563 } 1559 }
1564 1560
1565 FilePath snapshot_path_; 1561 FilePath snapshot_path_;
1566 ScopedTempDir snapshot_dir_; 1562 ScopedTempDir snapshot_dir_;
1567 }; 1563 };
1568 1564
1569 // See http://crbug.com/63022.
1570 #if defined(OS_LINUX)
1571 #define MAYBE_ContentLargerThanView FAILS_ContentLargerThanView
1572 #else
1573 #define MAYBE_ContentLargerThanView ContentLargerThanView
1574 #endif
1575 // Tests that taking a snapshot when the content is larger than the view 1565 // Tests that taking a snapshot when the content is larger than the view
1576 // produces a snapshot equal to the content size. 1566 // produces a snapshot equal to the content size.
1577 TEST_F(AutomationProxySnapshotTest, MAYBE_ContentLargerThanView) { 1567 TEST_F(AutomationProxySnapshotTest, ContentLargerThanView) {
1568 const char kReferenceMd5[] = "3d594850fd25cb116338cb3610afe18e";
1578 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); 1569 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
1579 ASSERT_TRUE(browser.get()); 1570 ASSERT_TRUE(browser.get());
1580
1581 // Resize the window to guarantee that the content is larger than the view.
1582 scoped_refptr<WindowProxy> window(browser->GetWindow());
1583 ASSERT_TRUE(window.get());
1584 ASSERT_TRUE(window->SetBounds(gfx::Rect(300, 400)));
1585
1586 scoped_refptr<TabProxy> tab(browser->GetTab(0)); 1571 scoped_refptr<TabProxy> tab(browser->GetTab(0));
1587 ASSERT_TRUE(tab.get()); 1572 ASSERT_TRUE(tab.get());
1588 1573
1589 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, 1574 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS,
1590 tab->NavigateToURL(GetTestUrl("set_size.html", "600,800"))); 1575 tab->NavigateToURL(GetTestUrl("set_size.html", "2000,2500")));
1591 1576
1592 ASSERT_TRUE(tab->CaptureEntirePageAsPNG(snapshot_path_)); 1577 ASSERT_TRUE(tab->CaptureEntirePageAsPNG(snapshot_path_));
1593 1578
1594 SkBitmap bitmap; 1579 std::string data;
1595 ASSERT_NO_FATAL_FAILURE(AssertReadPNG(snapshot_path_, &bitmap)); 1580 ASSERT_NO_FATAL_FAILURE(AssertReadPNG(snapshot_path_, &data));
1596 ASSERT_EQ(600, bitmap.width()); 1581 EXPECT_STREQ(kReferenceMd5, base::MD5String(data).c_str());
1597 ASSERT_EQ(800, bitmap.height()); 1582 if (CommandLine::ForCurrentProcess()->HasSwitch("dump-test-image")) {
1583 FilePath path(FILE_PATH_LITERAL("snapshot.png"));
1584 EXPECT_EQ(file_util::WriteFile(path, &data[0], data.length()),
1585 static_cast<int>(data.length()));
1586 }
1598 } 1587 }
1599
1600 // Tests taking a large snapshot works.
1601 #if defined(OS_LINUX)
1602 // See http://code.google.com/p/chromium/issues/detail?id=89777
1603 #define MAYBE_LargeSnapshot DISABLED_LargeSnapshot
1604 #else
1605 #define MAYBE_LargeSnapshot LargeSnapshot
1606 #endif
1607 TEST_F(AutomationProxySnapshotTest, MAYBE_LargeSnapshot) {
1608 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
1609 ASSERT_TRUE(browser.get());
1610
1611 scoped_refptr<TabProxy> tab(browser->GetTab(0));
1612 ASSERT_TRUE(tab.get());
1613
1614 // 2000x2000 creates an approximately 15 MB bitmap.
1615 // Don't increase this too much. At least my linux box has SHMMAX set at
1616 // 32 MB.
1617 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS,
1618 tab->NavigateToURL(GetTestUrl("set_size.html", "2000,2000")));
1619
1620 ASSERT_TRUE(tab->CaptureEntirePageAsPNG(snapshot_path_));
1621
1622 SkBitmap bitmap;
1623 ASSERT_NO_FATAL_FAILURE(AssertReadPNG(snapshot_path_, &bitmap));
1624 ASSERT_EQ(2000, bitmap.width());
1625 ASSERT_EQ(2000, bitmap.height());
1626 }
1627
1628 #if defined(OS_MACOSX)
1629 // Most pixels on mac are slightly off.
1630 #define MAYBE_ContentsCorrect DISABLED_ContentsCorrect
1631 #elif defined(OS_LINUX)
1632 // See http://crbug.com/63022.
1633 #define MAYBE_ContentsCorrect FAILS_ContentsCorrect
1634 #else
1635 #define MAYBE_ContentsCorrect ContentsCorrect
1636 #endif
1637
1638 // Tests that the snapshot contents are correct.
1639 TEST_F(AutomationProxySnapshotTest, MAYBE_ContentsCorrect) {
1640 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
1641 ASSERT_TRUE(browser.get());
1642
1643 const gfx::Size img_size(400, 300);
1644 scoped_refptr<WindowProxy> window(browser->GetWindow());
1645 ASSERT_TRUE(window.get());
1646 ASSERT_TRUE(window->SetBounds(gfx::Rect(img_size)));
1647
1648 scoped_refptr<TabProxy> tab(browser->GetTab(0));
1649 ASSERT_TRUE(tab.get());
1650
1651 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS,
1652 tab->NavigateToURL(GetTestUrl("just_image.html", "")));
1653
1654 ASSERT_TRUE(tab->CaptureEntirePageAsPNG(snapshot_path_));
1655
1656 SkBitmap snapshot_bmp;
1657 ASSERT_NO_FATAL_FAILURE(AssertReadPNG(snapshot_path_, &snapshot_bmp));
1658 ASSERT_EQ(img_size.width(), snapshot_bmp.width());
1659 ASSERT_EQ(img_size.height(), snapshot_bmp.height());
1660
1661 SkBitmap reference_bmp;
1662 ASSERT_NO_FATAL_FAILURE(AssertReadPNG(GetTestFilePath("image.png"),
1663 &reference_bmp));
1664 ASSERT_EQ(img_size.width(), reference_bmp.width());
1665 ASSERT_EQ(img_size.height(), reference_bmp.height());
1666
1667 SkAutoLockPixels lock_snapshot(snapshot_bmp);
1668 SkAutoLockPixels lock_reference(reference_bmp);
1669 int diff_pixels_count = 0;
1670 for (int x = 0; x < img_size.width(); ++x) {
1671 for (int y = 0; y < img_size.height(); ++y) {
1672 if (*snapshot_bmp.getAddr32(x, y) != *reference_bmp.getAddr32(x, y)) {
1673 ++diff_pixels_count;
1674 }
1675 }
1676 }
1677 ASSERT_EQ(diff_pixels_count, 0);
1678 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698