| OLD | NEW |
| 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 #ifndef CHROME_TEST_AUTOMATION_AUTOCOMPLETE_EDIT_PROXY_H_ | 5 #ifndef CHROME_TEST_AUTOMATION_AUTOCOMPLETE_EDIT_PROXY_H_ |
| 6 #define CHROME_TEST_AUTOMATION_AUTOCOMPLETE_EDIT_PROXY_H_ | 6 #define CHROME_TEST_AUTOMATION_AUTOCOMPLETE_EDIT_PROXY_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 13 #include "chrome/browser/autocomplete/autocomplete.h" | 13 #include "chrome/browser/autocomplete/autocomplete.h" |
| 14 #include "chrome/browser/autocomplete/autocomplete_match.h" | 14 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 15 #include "chrome/test/automation/automation_handle_tracker.h" | 15 #include "chrome/test/automation/automation_handle_tracker.h" |
| 16 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
| 17 #include "ipc/ipc_message.h" | |
| 18 #include "ipc/ipc_message_utils.h" | |
| 19 | 17 |
| 20 // The purpose of this class is to act as a serializable version of | 18 struct AutocompleteMatchData; |
| 21 // AutocompleteMatch. The reason for this class is because we don't want to | |
| 22 // serialize all elements of AutocompleteMatch and we want some data from the | |
| 23 // autocomplete provider without the hassle of serializing it. | |
| 24 struct AutocompleteMatchData { | |
| 25 public: | |
| 26 AutocompleteMatchData() | |
| 27 : relevance(0), | |
| 28 deletable(false), | |
| 29 inline_autocomplete_offset(0), | |
| 30 is_history_what_you_typed_match(false), | |
| 31 starred(false) { | |
| 32 } | |
| 33 | 19 |
| 34 explicit AutocompleteMatchData(const AutocompleteMatch& match) | |
| 35 : provider_name(match.provider->name()), | |
| 36 relevance(match.relevance), | |
| 37 deletable(match.deletable), | |
| 38 fill_into_edit(match.fill_into_edit), | |
| 39 inline_autocomplete_offset(match.inline_autocomplete_offset), | |
| 40 destination_url(match.destination_url), | |
| 41 contents(match.contents), | |
| 42 description(match.description), | |
| 43 is_history_what_you_typed_match(match.is_history_what_you_typed_match), | |
| 44 type(AutocompleteMatch::TypeToString(match.type)), | |
| 45 starred(match.starred) { | |
| 46 } | |
| 47 | |
| 48 std::string provider_name; | |
| 49 int relevance; | |
| 50 bool deletable; | |
| 51 string16 fill_into_edit; | |
| 52 size_t inline_autocomplete_offset; | |
| 53 GURL destination_url; | |
| 54 string16 contents; | |
| 55 string16 description; | |
| 56 bool is_history_what_you_typed_match; | |
| 57 std::string type; | |
| 58 bool starred; | |
| 59 }; | |
| 60 typedef std::vector<AutocompleteMatchData> Matches; | 20 typedef std::vector<AutocompleteMatchData> Matches; |
| 61 | 21 |
| 62 namespace IPC { | |
| 63 | |
| 64 template <> | |
| 65 struct ParamTraits<AutocompleteMatchData> { | |
| 66 typedef AutocompleteMatchData param_type; | |
| 67 static void Write(Message* m, const param_type& p) { | |
| 68 m->WriteString(p.provider_name); | |
| 69 m->WriteInt(p.relevance); | |
| 70 m->WriteBool(p.deletable); | |
| 71 m->WriteString16(p.fill_into_edit); | |
| 72 m->WriteSize(p.inline_autocomplete_offset); | |
| 73 m->WriteString(p.destination_url.possibly_invalid_spec()); | |
| 74 m->WriteString16(p.contents); | |
| 75 m->WriteString16(p.description); | |
| 76 m->WriteBool(p.is_history_what_you_typed_match); | |
| 77 m->WriteString(p.type); | |
| 78 m->WriteBool(p.starred); | |
| 79 } | |
| 80 | |
| 81 static bool Read(const Message* m, void** iter, param_type* r) { | |
| 82 std::string destination_url; | |
| 83 if (!m->ReadString(iter, &r->provider_name) || | |
| 84 !m->ReadInt(iter, &r->relevance) || | |
| 85 !m->ReadBool(iter, &r->deletable) || | |
| 86 !m->ReadString16(iter, &r->fill_into_edit) || | |
| 87 !m->ReadSize(iter, &r->inline_autocomplete_offset) || | |
| 88 !m->ReadString(iter, &destination_url) || | |
| 89 !m->ReadString16(iter, &r->contents) || | |
| 90 !m->ReadString16(iter, &r->description) || | |
| 91 !m->ReadBool(iter, &r->is_history_what_you_typed_match) || | |
| 92 !m->ReadString(iter, &r->type) || | |
| 93 !m->ReadBool(iter, &r->starred)) | |
| 94 return false; | |
| 95 r->destination_url = GURL(destination_url); | |
| 96 return true; | |
| 97 } | |
| 98 | |
| 99 static void Log(const param_type& p, std::string* l) { | |
| 100 l->append("["); | |
| 101 l->append(p.provider_name); | |
| 102 l->append(" "); | |
| 103 l->append(base::IntToString(p.relevance)); | |
| 104 l->append(" "); | |
| 105 l->append(p.deletable ? "true" : "false"); | |
| 106 l->append(" "); | |
| 107 LogParam(p.fill_into_edit, l); | |
| 108 l->append(" "); | |
| 109 l->append(base::IntToString(p.inline_autocomplete_offset)); | |
| 110 l->append(" "); | |
| 111 l->append(p.destination_url.spec()); | |
| 112 l->append(" "); | |
| 113 LogParam(p.contents, l); | |
| 114 l->append(" "); | |
| 115 LogParam(p.description, l); | |
| 116 l->append(" "); | |
| 117 l->append(p.is_history_what_you_typed_match ? "true" : "false"); | |
| 118 l->append(" "); | |
| 119 l->append(p.type); | |
| 120 l->append(" "); | |
| 121 l->append(p.starred ? "true" : "false"); | |
| 122 l->append("]"); | |
| 123 } | |
| 124 }; | |
| 125 } // namespace IPC | |
| 126 | |
| 127 class AutocompleteEditProxy : public AutomationResourceProxy { | 22 class AutocompleteEditProxy : public AutomationResourceProxy { |
| 128 public: | 23 public: |
| 129 AutocompleteEditProxy(AutomationMessageSender* sender, | 24 AutocompleteEditProxy(AutomationMessageSender* sender, |
| 130 AutomationHandleTracker* tracker, | 25 AutomationHandleTracker* tracker, |
| 131 int handle) | 26 int handle) |
| 132 : AutomationResourceProxy(tracker, sender, handle) {} | 27 : AutomationResourceProxy(tracker, sender, handle) {} |
| 133 virtual ~AutocompleteEditProxy() {} | 28 virtual ~AutocompleteEditProxy() {} |
| 134 | 29 |
| 135 // All these functions return true if the autocomplete edit is valid and | 30 // All these functions return true if the autocomplete edit is valid and |
| 136 // there are no IPC errors. | 31 // there are no IPC errors. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 156 // Waits for all queries to autocomplete providers to complete. | 51 // Waits for all queries to autocomplete providers to complete. |
| 157 // |wait_timeout_ms| gives the number of milliseconds to wait for the query | 52 // |wait_timeout_ms| gives the number of milliseconds to wait for the query |
| 158 // to finish. Returns false if IPC call failed or if the function times out. | 53 // to finish. Returns false if IPC call failed or if the function times out. |
| 159 bool WaitForQuery(int wait_timeout_ms) const; | 54 bool WaitForQuery(int wait_timeout_ms) const; |
| 160 | 55 |
| 161 private: | 56 private: |
| 162 DISALLOW_COPY_AND_ASSIGN(AutocompleteEditProxy); | 57 DISALLOW_COPY_AND_ASSIGN(AutocompleteEditProxy); |
| 163 }; | 58 }; |
| 164 | 59 |
| 165 #endif // CHROME_TEST_AUTOMATION_AUTOCOMPLETE_EDIT_PROXY_H_ | 60 #endif // CHROME_TEST_AUTOMATION_AUTOCOMPLETE_EDIT_PROXY_H_ |
| OLD | NEW |