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

Side by Side Diff: chrome/browser/automation/testing_automation_provider.cc

Issue 8274012: Wait for URLBlacklist update tasks on automation tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reviewed 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
« no previous file with comments | « no previous file | chrome/test/functional/PYAUTO_TESTS » ('j') | 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) 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/browser/automation/testing_automation_provider.h" 5 #include "chrome/browser/automation/testing_automation_provider.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/file_path.h" 15 #include "base/file_path.h"
16 #include "base/json/json_reader.h" 16 #include "base/json/json_reader.h"
17 #include "base/json/json_writer.h" 17 #include "base/json/json_writer.h"
18 #include "base/json/string_escape.h" 18 #include "base/json/string_escape.h"
19 #include "base/path_service.h" 19 #include "base/path_service.h"
20 #include "base/process.h" 20 #include "base/process.h"
21 #include "base/process_util.h" 21 #include "base/process_util.h"
22 #include "base/stringprintf.h" 22 #include "base/stringprintf.h"
23 #include "base/synchronization/waitable_event.h"
23 #include "base/threading/thread_restrictions.h" 24 #include "base/threading/thread_restrictions.h"
24 #include "base/time.h" 25 #include "base/time.h"
25 #include "base/utf_string_conversions.h" 26 #include "base/utf_string_conversions.h"
26 #include "chrome/app/chrome_command_ids.h" 27 #include "chrome/app/chrome_command_ids.h"
27 #include "chrome/browser/autocomplete/autocomplete.h" 28 #include "chrome/browser/autocomplete/autocomplete.h"
28 #include "chrome/browser/autocomplete/autocomplete_edit.h" 29 #include "chrome/browser/autocomplete/autocomplete_edit.h"
29 #include "chrome/browser/autocomplete/autocomplete_match.h" 30 #include "chrome/browser/autocomplete/autocomplete_match.h"
30 #include "chrome/browser/autofill/autofill_manager.h" 31 #include "chrome/browser/autofill/autofill_manager.h"
31 #include "chrome/browser/autofill/credit_card.h" 32 #include "chrome/browser/autofill/credit_card.h"
32 #include "chrome/browser/autofill/personal_data_manager.h" 33 #include "chrome/browser/autofill/personal_data_manager.h"
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 } 170 }
170 171
171 virtual std::string GetHTMLContents() { return contents_; } 172 virtual std::string GetHTMLContents() { return contents_; }
172 173
173 private: 174 private:
174 const std::string contents_; 175 const std::string contents_;
175 176
176 DISALLOW_COPY_AND_ASSIGN(AutomationInterstitialPage); 177 DISALLOW_COPY_AND_ASSIGN(AutomationInterstitialPage);
177 }; 178 };
178 179
180 // Waits for all currently pending tasks on |identifier| to be processed before
181 // returning. Returns false if |identifier| is the current thread, or a task
182 // could not be posted. Returns true otherwise.
183 bool WaitForPendingTasksOn(BrowserThread::ID identifier) {
184 // Avoid deadlocking self.
185 if (BrowserThread::CurrentlyOn(identifier))
186 return false;
187 base::WaitableEvent event(true, // manual reset
188 false); // not initially signaled
189 if (!BrowserThread::PostTask(
190 identifier,
191 FROM_HERE,
192 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event))))
193 return false;
194 event.Wait();
Paweł Hajdan Jr. 2011/10/19 09:20:02 I think this also returns bool, so please return e
195 return true;
196 }
197
179 } // namespace 198 } // namespace
180 199
181 TestingAutomationProvider::TestingAutomationProvider(Profile* profile) 200 TestingAutomationProvider::TestingAutomationProvider(Profile* profile)
182 : AutomationProvider(profile), 201 : AutomationProvider(profile),
183 #if defined(TOOLKIT_VIEWS) 202 #if defined(TOOLKIT_VIEWS)
184 popup_menu_waiter_(NULL), 203 popup_menu_waiter_(NULL),
185 #endif 204 #endif
186 redirect_query_(0) { 205 redirect_query_(0) {
187 BrowserList::AddObserver(this); 206 BrowserList::AddObserver(this);
188 registrar_.Add(this, chrome::NOTIFICATION_SESSION_END, 207 registrar_.Add(this, chrome::NOTIFICATION_SESSION_END,
(...skipping 2538 matching lines...) Expand 10 before | Expand all | Expand 10 after
2727 reply.SendError("Invalid action"); 2746 reply.SendError("Invalid action");
2728 } 2747 }
2729 2748
2730 namespace { 2749 namespace {
2731 2750
2732 // Task to get info about BrowserChildProcessHost. Must run on IO thread to 2751 // Task to get info about BrowserChildProcessHost. Must run on IO thread to
2733 // honor the semantics of BrowserChildProcessHost. 2752 // honor the semantics of BrowserChildProcessHost.
2734 // Used by AutomationProvider::GetBrowserInfo(). 2753 // Used by AutomationProvider::GetBrowserInfo().
2735 class GetChildProcessHostInfoTask : public Task { 2754 class GetChildProcessHostInfoTask : public Task {
2736 public: 2755 public:
2737 GetChildProcessHostInfoTask(base::WaitableEvent* event, 2756 explicit GetChildProcessHostInfoTask(ListValue* child_processes)
2738 ListValue* child_processes) 2757 : child_processes_(child_processes) {}
2739 : event_(event),
2740 child_processes_(child_processes) {}
2741 2758
2742 virtual void Run() { 2759 virtual void Run() OVERRIDE {
2743 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 2760 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
2744 for (BrowserChildProcessHost::Iterator iter; !iter.Done(); ++iter) { 2761 for (BrowserChildProcessHost::Iterator iter; !iter.Done(); ++iter) {
2745 // Only add processes which are already started, 2762 // Only add processes which are already started,
2746 // since we need their handle. 2763 // since we need their handle.
2747 if ((*iter)->handle() == base::kNullProcessHandle) { 2764 if ((*iter)->handle() == base::kNullProcessHandle) {
2748 continue; 2765 continue;
2749 } 2766 }
2750 ChildProcessInfo* info = *iter; 2767 ChildProcessInfo* info = *iter;
2751 DictionaryValue* item = new DictionaryValue; 2768 DictionaryValue* item = new DictionaryValue;
2752 item->SetString("name", info->name()); 2769 item->SetString("name", info->name());
2753 item->SetString("type", 2770 item->SetString("type",
2754 ChildProcessInfo::GetTypeNameInEnglish(info->type())); 2771 ChildProcessInfo::GetTypeNameInEnglish(info->type()));
2755 item->SetInteger("pid", base::GetProcId(info->handle())); 2772 item->SetInteger("pid", base::GetProcId(info->handle()));
2756 child_processes_->Append(item); 2773 child_processes_->Append(item);
2757 } 2774 }
2758 event_->Signal();
2759 } 2775 }
2760 2776
2761 private: 2777 private:
2762 base::WaitableEvent* const event_; // weak
2763 ListValue* child_processes_; 2778 ListValue* child_processes_;
2764 2779
2765 DISALLOW_COPY_AND_ASSIGN(GetChildProcessHostInfoTask); 2780 DISALLOW_COPY_AND_ASSIGN(GetChildProcessHostInfoTask);
2766 }; 2781 };
2767 2782
2768 } // namespace 2783 } // namespace
2769 2784
2770 // Sample json input: { "command": "GetBrowserInfo" } 2785 // Sample json input: { "command": "GetBrowserInfo" }
2771 // Refer to GetBrowserInfo() in chrome/test/pyautolib/pyauto.py for 2786 // Refer to GetBrowserInfo() in chrome/test/pyautolib/pyauto.py for
2772 // sample json output. 2787 // sample json output.
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
2874 #else 2889 #else
2875 int flags = ChildProcessHost::CHILD_NORMAL; 2890 int flags = ChildProcessHost::CHILD_NORMAL;
2876 #endif 2891 #endif
2877 2892
2878 return_value->SetString("child_process_path", 2893 return_value->SetString("child_process_path",
2879 ChildProcessHost::GetChildPath(flags).value()); 2894 ChildProcessHost::GetChildPath(flags).value());
2880 // Child processes are the processes for plugins and other workers. 2895 // Child processes are the processes for plugins and other workers.
2881 // Add all child processes in a list of dictionaries, one dictionary item 2896 // Add all child processes in a list of dictionaries, one dictionary item
2882 // per child process. 2897 // per child process.
2883 ListValue* child_processes = new ListValue; 2898 ListValue* child_processes = new ListValue;
2884 base::WaitableEvent event(true /* manual reset */,
2885 false /* not initially signaled */);
2886 CHECK(BrowserThread::PostTask( 2899 CHECK(BrowserThread::PostTask(
2887 BrowserThread::IO, FROM_HERE, 2900 BrowserThread::IO, FROM_HERE,
2888 new GetChildProcessHostInfoTask(&event, child_processes))); 2901 new GetChildProcessHostInfoTask(child_processes)));
2889 event.Wait(); 2902 CHECK(WaitForPendingTasksOn(BrowserThread::IO));
jam 2011/10/19 23:56:27 instead of blocking one thread on another, why not
2890 return_value->Set("child_processes", child_processes); 2903 return_value->Set("child_processes", child_processes);
2891 2904
2892 // Add all extension processes in a list of dictionaries, one dictionary 2905 // Add all extension processes in a list of dictionaries, one dictionary
2893 // item per extension process. 2906 // item per extension process.
2894 ListValue* extension_views = new ListValue; 2907 ListValue* extension_views = new ListValue;
2895 ProfileManager* profile_manager = g_browser_process->profile_manager(); 2908 ProfileManager* profile_manager = g_browser_process->profile_manager();
2896 std::vector<Profile*> profiles(profile_manager->GetLoadedProfiles()); 2909 std::vector<Profile*> profiles(profile_manager->GetLoadedProfiles());
2897 for (size_t i = 0; i < profiles.size(); ++i) { 2910 for (size_t i = 0; i < profiles.size(); ++i) {
2898 ExtensionProcessManager* process_manager = 2911 ExtensionProcessManager* process_manager =
2899 profiles[i]->GetExtensionProcessManager(); 2912 profiles[i]->GetExtensionProcessManager();
(...skipping 2994 matching lines...) Expand 10 before | Expand all | Expand 10 after
5894 } 5907 }
5895 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(providers); ++i) { 5908 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(providers); ++i) {
5896 DictionaryValue* policies = NULL; 5909 DictionaryValue* policies = NULL;
5897 if (args->GetDictionary(providers[i].name, &policies) && policies) { 5910 if (args->GetDictionary(providers[i].name, &policies) && policies) {
5898 policy::PolicyMap* map = new policy::PolicyMap; 5911 policy::PolicyMap* map = new policy::PolicyMap;
5899 map->LoadFrom(policies, list); 5912 map->LoadFrom(policies, list);
5900 providers[i].provider->OverridePolicies(map); 5913 providers[i].provider->OverridePolicies(map);
5901 } 5914 }
5902 } 5915 }
5903 5916
5917 // OverridePolicies() triggers preference updates, which triggers preference
5918 // listeners. Some policies (e.g. URLBlacklist) post tasks to other message
5919 // loops before they start being enforced; make sure those tasks have
5920 // finished.
5921 CHECK(WaitForPendingTasksOn(BrowserThread::IO));
jam 2011/10/19 23:56:27 ditto
5922 CHECK(WaitForPendingTasksOn(BrowserThread::FILE));
5923 CHECK(WaitForPendingTasksOn(BrowserThread::IO));
5924
5904 reply.SendSuccess(NULL); 5925 reply.SendSuccess(NULL);
5905 #endif // defined(OFFICIAL_BUILD) 5926 #endif // defined(OFFICIAL_BUILD)
5906 } 5927 }
5907 5928
5908 void TestingAutomationProvider::GetPolicyDefinitionList( 5929 void TestingAutomationProvider::GetPolicyDefinitionList(
5909 DictionaryValue* args, 5930 DictionaryValue* args,
5910 IPC::Message* reply_message) { 5931 IPC::Message* reply_message) {
5911 AutomationJSONReply reply(this, reply_message); 5932 AutomationJSONReply reply(this, reply_message);
5912 5933
5913 #if !defined(ENABLE_CONFIGURATION_POLICY) 5934 #if !defined(ENABLE_CONFIGURATION_POLICY)
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
6528 6549
6529 Send(reply_message_); 6550 Send(reply_message_);
6530 redirect_query_ = 0; 6551 redirect_query_ = 0;
6531 reply_message_ = NULL; 6552 reply_message_ = NULL;
6532 } 6553 }
6533 6554
6534 void TestingAutomationProvider::OnRemoveProvider() { 6555 void TestingAutomationProvider::OnRemoveProvider() {
6535 if (g_browser_process) 6556 if (g_browser_process)
6536 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); 6557 g_browser_process->GetAutomationProviderList()->RemoveProvider(this);
6537 } 6558 }
OLDNEW
« no previous file with comments | « no previous file | chrome/test/functional/PYAUTO_TESTS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698