OLD | NEW |
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 "chrome/test/base/ui_test_utils.h" | 5 #include "chrome/test/base/ui_test_utils.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
895 if (running_) | 895 if (running_) |
896 MessageLoopForUI::current()->Quit(); | 896 MessageLoopForUI::current()->Quit(); |
897 } else { | 897 } else { |
898 sources_seen_.insert(source.map_key()); | 898 sources_seen_.insert(source.map_key()); |
899 } | 899 } |
900 } | 900 } |
901 | 901 |
902 TitleWatcher::TitleWatcher(TabContents* tab_contents, | 902 TitleWatcher::TitleWatcher(TabContents* tab_contents, |
903 const string16& expected_title) | 903 const string16& expected_title) |
904 : expected_tab_(tab_contents), | 904 : expected_tab_(tab_contents), |
905 expected_title_(expected_title), | 905 expected_title_observed_(false), |
906 title_observed_(false), | |
907 quit_loop_on_observation_(false) { | 906 quit_loop_on_observation_(false) { |
908 EXPECT_TRUE(tab_contents != NULL); | 907 EXPECT_TRUE(tab_contents != NULL); |
| 908 expected_titles_.push_back(expected_title); |
909 notification_registrar_.Add(this, | 909 notification_registrar_.Add(this, |
910 content::NOTIFICATION_TAB_CONTENTS_TITLE_UPDATED, | 910 content::NOTIFICATION_TAB_CONTENTS_TITLE_UPDATED, |
911 Source<TabContents>(tab_contents)); | 911 Source<TabContents>(tab_contents)); |
912 } | 912 } |
913 | 913 |
| 914 void TitleWatcher::AlsoWaitForTitle(const string16& expected_title) { |
| 915 expected_titles_.push_back(expected_title); |
| 916 } |
| 917 |
914 TitleWatcher::~TitleWatcher() { | 918 TitleWatcher::~TitleWatcher() { |
915 } | 919 } |
916 | 920 |
917 bool TitleWatcher::Wait() { | 921 const string16& TitleWatcher::WaitAndGetTitle() { |
918 if (title_observed_) | 922 if (expected_title_observed_) |
919 return true; | 923 return observed_title_; |
920 quit_loop_on_observation_ = true; | 924 quit_loop_on_observation_ = true; |
921 ui_test_utils::RunMessageLoop(); | 925 ui_test_utils::RunMessageLoop(); |
922 return title_observed_; | 926 return observed_title_; |
923 } | 927 } |
924 | 928 |
925 void TitleWatcher::Observe(int type, | 929 void TitleWatcher::Observe(int type, |
926 const NotificationSource& source, | 930 const NotificationSource& source, |
927 const NotificationDetails& details) { | 931 const NotificationDetails& details) { |
928 if (type != content::NOTIFICATION_TAB_CONTENTS_TITLE_UPDATED) | 932 if (type != content::NOTIFICATION_TAB_CONTENTS_TITLE_UPDATED) |
929 return; | 933 return; |
930 | 934 |
931 TabContents* source_contents = Source<TabContents>(source).ptr(); | 935 TabContents* source_contents = Source<TabContents>(source).ptr(); |
932 ASSERT_EQ(expected_tab_, source_contents); | 936 ASSERT_EQ(expected_tab_, source_contents); |
933 if (source_contents->GetTitle() != expected_title_) | 937 std::vector<string16>::const_iterator it = |
| 938 std::find(expected_titles_.begin(), |
| 939 expected_titles_.end(), |
| 940 source_contents->GetTitle()); |
| 941 if (it == expected_titles_.end()) |
934 return; | 942 return; |
935 | 943 observed_title_ = *it; |
936 title_observed_ = true; | 944 expected_title_observed_ = true; |
937 if (quit_loop_on_observation_) | 945 if (quit_loop_on_observation_) |
938 MessageLoopForUI::current()->Quit(); | 946 MessageLoopForUI::current()->Quit(); |
939 } | 947 } |
940 | 948 |
941 DOMMessageQueue::DOMMessageQueue() { | 949 DOMMessageQueue::DOMMessageQueue() { |
942 registrar_.Add(this, chrome::NOTIFICATION_DOM_OPERATION_RESPONSE, | 950 registrar_.Add(this, chrome::NOTIFICATION_DOM_OPERATION_RESPONSE, |
943 NotificationService::AllSources()); | 951 NotificationService::AllSources()); |
944 } | 952 } |
945 | 953 |
946 DOMMessageQueue::~DOMMessageQueue() {} | 954 DOMMessageQueue::~DOMMessageQueue() {} |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1043 return taker.TakeRenderWidgetSnapshot(rwh, page_size, page_size, bitmap); | 1051 return taker.TakeRenderWidgetSnapshot(rwh, page_size, page_size, bitmap); |
1044 } | 1052 } |
1045 | 1053 |
1046 bool TakeEntirePageSnapshot(RenderViewHost* rvh, SkBitmap* bitmap) { | 1054 bool TakeEntirePageSnapshot(RenderViewHost* rvh, SkBitmap* bitmap) { |
1047 DCHECK(bitmap); | 1055 DCHECK(bitmap); |
1048 SnapshotTaker taker; | 1056 SnapshotTaker taker; |
1049 return taker.TakeEntirePageSnapshot(rvh, bitmap); | 1057 return taker.TakeEntirePageSnapshot(rvh, bitmap); |
1050 } | 1058 } |
1051 | 1059 |
1052 } // namespace ui_test_utils | 1060 } // namespace ui_test_utils |
OLD | NEW |