Chromium Code Reviews| 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::AddTitle(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::Wait() { |
| 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 for (std::vector<string16>::const_iterator it = expected_titles_.begin(); |
|
eroman
2011/08/03 00:32:24
[optional] If you prefer, could also used std::fin
mmenke
2011/08/03 15:44:17
Good idea, done.
| |
| 934 return; | 938 it != expected_titles_.end(); |
| 935 | 939 ++it) { |
| 936 title_observed_ = true; | 940 if (*it == source_contents->GetTitle()) { |
| 937 if (quit_loop_on_observation_) | 941 observed_title_ = source_contents->GetTitle(); |
|
eroman
2011/08/03 00:32:24
BTW I don't know anything about the GetTitle() fun
mmenke
2011/08/03 15:44:17
It can't change, but switching to using .find() re
| |
| 938 MessageLoopForUI::current()->Quit(); | 942 expected_title_observed_ = true; |
| 943 if (quit_loop_on_observation_) | |
| 944 MessageLoopForUI::current()->Quit(); | |
| 945 return; | |
| 946 } | |
| 947 } | |
| 939 } | 948 } |
| 940 | 949 |
| 941 DOMMessageQueue::DOMMessageQueue() { | 950 DOMMessageQueue::DOMMessageQueue() { |
| 942 registrar_.Add(this, chrome::NOTIFICATION_DOM_OPERATION_RESPONSE, | 951 registrar_.Add(this, chrome::NOTIFICATION_DOM_OPERATION_RESPONSE, |
| 943 NotificationService::AllSources()); | 952 NotificationService::AllSources()); |
| 944 } | 953 } |
| 945 | 954 |
| 946 DOMMessageQueue::~DOMMessageQueue() {} | 955 DOMMessageQueue::~DOMMessageQueue() {} |
| 947 | 956 |
| 948 void DOMMessageQueue::Observe(int type, | 957 void DOMMessageQueue::Observe(int type, |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1043 return taker.TakeRenderWidgetSnapshot(rwh, page_size, page_size, bitmap); | 1052 return taker.TakeRenderWidgetSnapshot(rwh, page_size, page_size, bitmap); |
| 1044 } | 1053 } |
| 1045 | 1054 |
| 1046 bool TakeEntirePageSnapshot(RenderViewHost* rvh, SkBitmap* bitmap) { | 1055 bool TakeEntirePageSnapshot(RenderViewHost* rvh, SkBitmap* bitmap) { |
| 1047 DCHECK(bitmap); | 1056 DCHECK(bitmap); |
| 1048 SnapshotTaker taker; | 1057 SnapshotTaker taker; |
| 1049 return taker.TakeEntirePageSnapshot(rvh, bitmap); | 1058 return taker.TakeEntirePageSnapshot(rvh, bitmap); |
| 1050 } | 1059 } |
| 1051 | 1060 |
| 1052 } // namespace ui_test_utils | 1061 } // namespace ui_test_utils |
| OLD | NEW |