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

Side by Side Diff: chrome/test/ui_test_utils.cc

Issue 4723006: Add test fixture for GPU browser tests which do image comparisons.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 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
« chrome/test/ui_test_utils.h ('K') | « chrome/test/ui_test_utils.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/test/ui_test_utils.h" 5 #include "chrome/test/ui_test_utils.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/callback.h"
9 #include "base/command_line.h" 10 #include "base/command_line.h"
10 #include "base/file_path.h" 11 #include "base/file_path.h"
11 #include "base/json/json_reader.h" 12 #include "base/json/json_reader.h"
12 #include "base/message_loop.h" 13 #include "base/message_loop.h"
13 #include "base/path_service.h" 14 #include "base/path_service.h"
14 #include "base/process_util.h" 15 #include "base/process_util.h"
16 #include "base/scoped_ptr.h"
15 #include "base/utf_string_conversions.h" 17 #include "base/utf_string_conversions.h"
16 #include "base/values.h" 18 #include "base/values.h"
17 #include "chrome/browser/automation/ui_controls.h" 19 #include "chrome/browser/automation/ui_controls.h"
18 #include "chrome/browser/browser.h" 20 #include "chrome/browser/browser.h"
19 #include "chrome/browser/browser_list.h" 21 #include "chrome/browser/browser_list.h"
22 #include "chrome/browser/browser_process.h"
20 #include "chrome/browser/browser_window.h" 23 #include "chrome/browser/browser_window.h"
21 #include "chrome/browser/dom_operation_notification_details.h" 24 #include "chrome/browser/dom_operation_notification_details.h"
22 #include "chrome/browser/download/download_item.h" 25 #include "chrome/browser/download/download_item.h"
23 #include "chrome/browser/download/download_manager.h" 26 #include "chrome/browser/download/download_manager.h"
24 #include "chrome/browser/profile.h" 27 #include "chrome/browser/profile.h"
25 #include "chrome/browser/renderer_host/render_process_host.h" 28 #include "chrome/browser/renderer_host/render_process_host.h"
26 #include "chrome/browser/renderer_host/render_view_host.h" 29 #include "chrome/browser/renderer_host/render_view_host.h"
27 #include "chrome/browser/tab_contents/navigation_controller.h" 30 #include "chrome/browser/tab_contents/navigation_controller.h"
28 #include "chrome/browser/tab_contents/navigation_entry.h" 31 #include "chrome/browser/tab_contents/navigation_entry.h"
29 #include "chrome/browser/tab_contents/tab_contents.h" 32 #include "chrome/browser/tab_contents/tab_contents.h"
33 #include "chrome/browser/tab_contents/thumbnail_generator.h"
30 #include "chrome/common/chrome_paths.h" 34 #include "chrome/common/chrome_paths.h"
31 #include "chrome/common/extensions/extension_action.h" 35 #include "chrome/common/extensions/extension_action.h"
32 #include "chrome/common/notification_type.h" 36 #include "chrome/common/notification_type.h"
33 #include "chrome/test/automation/javascript_execution_controller.h" 37 #include "chrome/test/automation/javascript_execution_controller.h"
34 #include "chrome/test/bookmark_load_observer.h" 38 #include "chrome/test/bookmark_load_observer.h"
35 #if defined(TOOLKIT_VIEWS) 39 #if defined(TOOLKIT_VIEWS)
36 #include "views/focus/accelerator_handler.h" 40 #include "views/focus/accelerator_handler.h"
37 #endif 41 #endif
42 #include "gfx/size.h"
38 #include "googleurl/src/gurl.h" 43 #include "googleurl/src/gurl.h"
39 #include "net/base/net_util.h" 44 #include "net/base/net_util.h"
40 #include "testing/gtest/include/gtest/gtest.h" 45 #include "testing/gtest/include/gtest/gtest.h"
46 #include "third_party/skia/include/core/SkBitmap.h"
47 #include "third_party/skia/include/core/SkColor.h"
41 48
42 namespace ui_test_utils { 49 namespace ui_test_utils {
43 50
44 namespace { 51 namespace {
45 52
46 // Used to block until a navigation completes. 53 // Used to block until a navigation completes.
47 class NavigationNotificationObserver : public NotificationObserver { 54 class NavigationNotificationObserver : public NotificationObserver {
48 public: 55 public:
49 NavigationNotificationObserver(NavigationController* controller, 56 NavigationNotificationObserver(NavigationController* controller,
50 int number_of_navigations) 57 int number_of_navigations)
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 const NotificationDetails& details) { 800 const NotificationDetails& details) {
794 if (waiting_for_ == source) { 801 if (waiting_for_ == source) {
795 seen_ = true; 802 seen_ = true;
796 if (running_) 803 if (running_)
797 MessageLoopForUI::current()->Quit(); 804 MessageLoopForUI::current()->Quit();
798 } else { 805 } else {
799 sources_seen_.insert(source.map_key()); 806 sources_seen_.insert(source.map_key());
800 } 807 }
801 } 808 }
802 809
810 DOMMessageQueue::DOMMessageQueue() {
811 registrar_.Add(this, NotificationType::DOM_OPERATION_RESPONSE,
812 NotificationService::AllSources());
813 }
814
815 void DOMMessageQueue::Observe(NotificationType type,
816 const NotificationSource& source,
817 const NotificationDetails& details) {
818 Details<DomOperationNotificationDetails> dom_op_details(details);
819 Source<RenderViewHost> sender(source);
820 message_queue_.push(dom_op_details->json());
821 if (waiting_for_message_) {
822 waiting_for_message_ = false;
823 MessageLoopForUI::current()->Quit();
824 }
825 }
826
827 bool DOMMessageQueue::WaitForMessage(std::string* message) {
828 if (message_queue_.empty()) {
829 waiting_for_message_ = true;
830 // This will be quit when a new message comes in.
831 RunMessageLoop();
832 }
833 // The queue should not be empty, unless we were quit because of a timeout.
834 if (message_queue_.empty())
835 return false;
836 if (message)
837 *message = message_queue_.front();
838 return true;
839 }
840
841 // Coordinates taking snapshots of a |RenderWidget|.
842 class SnapshotTaker {
843 public:
844 SnapshotTaker() {}
845
846 bool TakeSnapshot(RenderWidgetHost* rwh,
847 const gfx::Size& page_size,
848 const gfx::Size& desired_size,
849 SkBitmap* bitmap) WARN_UNUSED_RESULT {
850 bitmap_ = bitmap;
851 ThumbnailGenerator* generator = g_browser_process->GetThumbnailGenerator();
852 generator->StartThumbnailing();
853 // The thumbnail generator might not have been started early enough to be
854 // set as the painting observer for this widget.
855 rwh->set_painting_observer(generator);
856 snapshot_taken_ = false;
857 generator->AskForSnapshot(
858 rwh,
859 false, // don't use backing_store
860 NewCallback(this, &SnapshotTaker::OnSnapshotTaken),
861 page_size,
862 desired_size);
863 ui_test_utils::RunMessageLoop();
864 return snapshot_taken_;
865 }
866
867 bool TakeEntirePageSnapshot(RenderViewHost* rvh,
868 SkBitmap* bitmap) WARN_UNUSED_RESULT {
869 const wchar_t* script =
870 L"window.domAutomationController.send("
871 L" JSON.stringify([document.width, document.height]))";
872 std::string json;
873 if (!ui_test_utils::ExecuteJavaScriptAndExtractString(
874 rvh, L"", script, &json))
875 return false;
876
877 // Parse the JSON.
878 std::vector<int> dimensions;
879 scoped_ptr<Value> value(base::JSONReader::Read(json, true));
880 if (!value->IsType(Value::TYPE_LIST))
881 return false;
882 ListValue* list = static_cast<ListValue*>(value.get());
883 int width, height;
884 if (!list->GetInteger(0, &width) || !list->GetInteger(1, &height))
885 return false;
886
887 // Take the snapshot.
888 gfx::Size page_size(width, height);
889 return TakeSnapshot(rvh, page_size, page_size, bitmap);
890 }
891
892 private:
893 // Called when the ThumbnailGenerator has taken the snapshot.
894 void OnSnapshotTaken(const SkBitmap& bitmap) {
895 *bitmap_ = bitmap;
896 snapshot_taken_ = true;
897 MessageLoop::current()->Quit();
898 }
899
900 SkBitmap* bitmap_;
901 // Whether the snapshot was actually taken and received by this SnapshotTaker.
902 // This will be false if the test times out.
903 bool snapshot_taken_;
904
905 DISALLOW_COPY_AND_ASSIGN(SnapshotTaker);
906 };
907
908 bool TakeSnapshot(RenderWidgetHost* rwh,
909 const gfx::Size& page_size,
910 SkBitmap* bitmap) {
911 DCHECK(bitmap);
912 SnapshotTaker taker;
913 return taker.TakeSnapshot(rwh, page_size, page_size, bitmap);
914 }
915
916 bool TakeEntirePageSnapshot(RenderViewHost* rvh, SkBitmap* bitmap) {
917 DCHECK(bitmap);
918 SnapshotTaker taker;
919 return taker.TakeEntirePageSnapshot(rvh, bitmap);
920 }
921
803 } // namespace ui_test_utils 922 } // namespace ui_test_utils
OLDNEW
« chrome/test/ui_test_utils.h ('K') | « chrome/test/ui_test_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698