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

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

Issue 8294030: Fix snapshotting on linux by creating a separate automation path for (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 9 years, 2 months 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"
(...skipping 1494 matching lines...) Expand 10 before | Expand all | Expand 10 after
1505 1505
1506 // Allow some time for the popup to show up and close. 1506 // Allow some time for the popup to show up and close.
1507 base::PlatformThread::Sleep(TestTimeouts::action_timeout_ms()); 1507 base::PlatformThread::Sleep(TestTimeouts::action_timeout_ms());
1508 1508
1509 std::wstring expected(L"string"); 1509 std::wstring expected(L"string");
1510 std::wstring jscript = CreateJSString(L"\"" + expected + L"\""); 1510 std::wstring jscript = CreateJSString(L"\"" + expected + L"\"");
1511 std::wstring actual; 1511 std::wstring actual;
1512 ASSERT_TRUE(tab->ExecuteAndExtractString(L"", jscript, &actual)); 1512 ASSERT_TRUE(tab->ExecuteAndExtractString(L"", jscript, &actual));
1513 ASSERT_EQ(expected, actual); 1513 ASSERT_EQ(expected, actual);
1514 } 1514 }
1515
1516 class AutomationProxySnapshotTest : public UITest {
Paweł Hajdan Jr. 2011/10/18 10:21:35 The native testing environment for that code are U
kkania 2011/10/18 18:30:19 I was a bit too hasty to remove all these. I do th
1517 protected:
1518 AutomationProxySnapshotTest() {
1519 dom_automation_enabled_ = true;
1520 if (!snapshot_dir_.CreateUniqueTempDir())
1521 ADD_FAILURE() << "Unable to create temporary directory";
1522 else
1523 snapshot_path_ = snapshot_dir_.path().AppendASCII("snapshot.png");
1524 }
1525
1526 // Asserts that the given png file can be read and decoded into the given
1527 // bitmap.
1528 void AssertReadPNG(const FilePath& filename, SkBitmap* bitmap) {
1529 DCHECK(bitmap);
1530 ASSERT_TRUE(file_util::PathExists(filename));
1531
1532 int64 size64;
1533 ASSERT_TRUE(file_util::GetFileSize(filename, &size64));
1534 // Check that the file is not too big to read in (less than 100 MB).
1535 ASSERT_LT(size64, 1024 * 1024 * 100);
1536
1537 // Read and decode image.
1538 int size = static_cast<int>(size64);
1539 scoped_array<char> data(new char[size]);
1540 int bytes_read = file_util::ReadFile(filename, &data[0], size);
1541 ASSERT_EQ(size, bytes_read);
1542 ASSERT_TRUE(gfx::PNGCodec::Decode(
1543 reinterpret_cast<unsigned char*>(&data[0]),
1544 bytes_read,
1545 bitmap));
1546 }
1547
1548 // Returns the file path for the directory for these tests appended with
1549 // the given relative path.
1550 FilePath GetTestFilePath(const std::string& relative_path) {
1551 FilePath filename(test_data_directory_);
1552 return filename.AppendASCII("automation_proxy_snapshot")
1553 .AppendASCII(relative_path);
1554 }
1555
1556 GURL GetTestUrl(const std::string& relative_path, const std::string& query) {
1557 FilePath file_path = GetTestFilePath(relative_path);
1558 return ui_test_utils::GetFileUrlWithQuery(file_path, query);
1559 }
1560
1561 FilePath snapshot_path_;
1562 ScopedTempDir snapshot_dir_;
1563 };
1564
1565 // See http://crbug.com/63022.
1566 #if defined(OS_LINUX)
1567 #define MAYBE_ContentLargerThanView FAILS_ContentLargerThanView
1568 #else
1569 #define MAYBE_ContentLargerThanView ContentLargerThanView
1570 #endif
1571 // Tests that taking a snapshot when the content is larger than the view
1572 // produces a snapshot equal to the content size.
1573 TEST_F(AutomationProxySnapshotTest, MAYBE_ContentLargerThanView) {
1574 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
1575 ASSERT_TRUE(browser.get());
1576
1577 // Resize the window to guarantee that the content is larger than the view.
1578 scoped_refptr<WindowProxy> window(browser->GetWindow());
1579 ASSERT_TRUE(window.get());
1580 ASSERT_TRUE(window->SetBounds(gfx::Rect(300, 400)));
1581
1582 scoped_refptr<TabProxy> tab(browser->GetTab(0));
1583 ASSERT_TRUE(tab.get());
1584
1585 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS,
1586 tab->NavigateToURL(GetTestUrl("set_size.html", "600,800")));
1587
1588 ASSERT_TRUE(tab->CaptureEntirePageAsPNG(snapshot_path_));
1589
1590 SkBitmap bitmap;
1591 ASSERT_NO_FATAL_FAILURE(AssertReadPNG(snapshot_path_, &bitmap));
1592 ASSERT_EQ(600, bitmap.width());
1593 ASSERT_EQ(800, bitmap.height());
1594 }
1595
1596 // Tests taking a large snapshot works.
1597 #if defined(OS_LINUX)
1598 // See http://code.google.com/p/chromium/issues/detail?id=89777
1599 #define MAYBE_LargeSnapshot DISABLED_LargeSnapshot
1600 #else
1601 #define MAYBE_LargeSnapshot LargeSnapshot
1602 #endif
1603 TEST_F(AutomationProxySnapshotTest, MAYBE_LargeSnapshot) {
1604 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
1605 ASSERT_TRUE(browser.get());
1606
1607 scoped_refptr<TabProxy> tab(browser->GetTab(0));
1608 ASSERT_TRUE(tab.get());
1609
1610 // 2000x2000 creates an approximately 15 MB bitmap.
1611 // Don't increase this too much. At least my linux box has SHMMAX set at
1612 // 32 MB.
1613 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS,
1614 tab->NavigateToURL(GetTestUrl("set_size.html", "2000,2000")));
1615
1616 ASSERT_TRUE(tab->CaptureEntirePageAsPNG(snapshot_path_));
1617
1618 SkBitmap bitmap;
1619 ASSERT_NO_FATAL_FAILURE(AssertReadPNG(snapshot_path_, &bitmap));
1620 ASSERT_EQ(2000, bitmap.width());
1621 ASSERT_EQ(2000, bitmap.height());
1622 }
1623
1624 #if defined(OS_MACOSX)
1625 // Most pixels on mac are slightly off.
1626 #define MAYBE_ContentsCorrect DISABLED_ContentsCorrect
1627 #elif defined(OS_LINUX)
1628 // See http://crbug.com/63022.
1629 #define MAYBE_ContentsCorrect FAILS_ContentsCorrect
1630 #else
1631 #define MAYBE_ContentsCorrect ContentsCorrect
1632 #endif
1633
1634 // Tests that the snapshot contents are correct.
1635 TEST_F(AutomationProxySnapshotTest, MAYBE_ContentsCorrect) {
1636 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
1637 ASSERT_TRUE(browser.get());
1638
1639 const gfx::Size img_size(400, 300);
1640 scoped_refptr<WindowProxy> window(browser->GetWindow());
1641 ASSERT_TRUE(window.get());
1642 ASSERT_TRUE(window->SetBounds(gfx::Rect(img_size)));
1643
1644 scoped_refptr<TabProxy> tab(browser->GetTab(0));
1645 ASSERT_TRUE(tab.get());
1646
1647 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS,
1648 tab->NavigateToURL(GetTestUrl("just_image.html", "")));
1649
1650 ASSERT_TRUE(tab->CaptureEntirePageAsPNG(snapshot_path_));
1651
1652 SkBitmap snapshot_bmp;
1653 ASSERT_NO_FATAL_FAILURE(AssertReadPNG(snapshot_path_, &snapshot_bmp));
1654 ASSERT_EQ(img_size.width(), snapshot_bmp.width());
1655 ASSERT_EQ(img_size.height(), snapshot_bmp.height());
1656
1657 SkBitmap reference_bmp;
1658 ASSERT_NO_FATAL_FAILURE(AssertReadPNG(GetTestFilePath("image.png"),
1659 &reference_bmp));
1660 ASSERT_EQ(img_size.width(), reference_bmp.width());
1661 ASSERT_EQ(img_size.height(), reference_bmp.height());
1662
1663 SkAutoLockPixels lock_snapshot(snapshot_bmp);
1664 SkAutoLockPixels lock_reference(reference_bmp);
1665 int diff_pixels_count = 0;
1666 for (int x = 0; x < img_size.width(); ++x) {
1667 for (int y = 0; y < img_size.height(); ++y) {
1668 if (*snapshot_bmp.getAddr32(x, y) != *reference_bmp.getAddr32(x, y)) {
1669 ++diff_pixels_count;
1670 }
1671 }
1672 }
1673 ASSERT_EQ(diff_pixels_count, 0);
1674 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698