| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "content/shell/browser/layout_test/layout_test_bluetooth_chooser_factor
y.h" | 5 #include "content/shell/browser/layout_test/layout_test_bluetooth_chooser_factor
y.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "url/gurl.h" | 9 #include "url/origin.h" |
| 10 | 10 |
| 11 namespace content { | 11 namespace content { |
| 12 | 12 |
| 13 class WebContents; | 13 class WebContents; |
| 14 | 14 |
| 15 // Implements a Bluetooth chooser that records events it's sent, instead of | 15 // Implements a Bluetooth chooser that records events it's sent, instead of |
| 16 // showing a dialog. It allows tests to control how the chooser responds. | 16 // showing a dialog. It allows tests to control how the chooser responds. |
| 17 class LayoutTestBluetoothChooserFactory::Chooser : public BluetoothChooser { | 17 class LayoutTestBluetoothChooserFactory::Chooser : public BluetoothChooser { |
| 18 public: | 18 public: |
| 19 Chooser(const base::WeakPtr<LayoutTestBluetoothChooserFactory>& factory, | 19 Chooser(const base::WeakPtr<LayoutTestBluetoothChooserFactory>& factory, |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 : weak_this_(this) {} | 95 : weak_this_(this) {} |
| 96 | 96 |
| 97 LayoutTestBluetoothChooserFactory::~LayoutTestBluetoothChooserFactory() { | 97 LayoutTestBluetoothChooserFactory::~LayoutTestBluetoothChooserFactory() { |
| 98 SendEvent(BluetoothChooser::Event::CANCELLED, ""); | 98 SendEvent(BluetoothChooser::Event::CANCELLED, ""); |
| 99 } | 99 } |
| 100 | 100 |
| 101 scoped_ptr<BluetoothChooser> | 101 scoped_ptr<BluetoothChooser> |
| 102 LayoutTestBluetoothChooserFactory::RunBluetoothChooser( | 102 LayoutTestBluetoothChooserFactory::RunBluetoothChooser( |
| 103 WebContents* web_contents, | 103 WebContents* web_contents, |
| 104 const BluetoothChooser::EventHandler& event_handler, | 104 const BluetoothChooser::EventHandler& event_handler, |
| 105 const GURL& origin) { | 105 const url::Origin& origin) { |
| 106 std::string event = "chooser-opened("; | 106 std::string event = "chooser-opened("; |
| 107 event += origin.spec(); | 107 event += origin.Serialize(); |
| 108 event += ")"; | 108 event += ")"; |
| 109 events_.push_back(event); | 109 events_.push_back(event); |
| 110 return make_scoped_ptr(new Chooser(weak_this_.GetWeakPtr(), event_handler)); | 110 return make_scoped_ptr(new Chooser(weak_this_.GetWeakPtr(), event_handler)); |
| 111 } | 111 } |
| 112 | 112 |
| 113 std::vector<std::string> | 113 std::vector<std::string> |
| 114 LayoutTestBluetoothChooserFactory::GetAndResetEvents() { | 114 LayoutTestBluetoothChooserFactory::GetAndResetEvents() { |
| 115 std::vector<std::string> result; | 115 std::vector<std::string> result; |
| 116 result.swap(events_); | 116 result.swap(events_); |
| 117 return result; | 117 return result; |
| 118 } | 118 } |
| 119 | 119 |
| 120 void LayoutTestBluetoothChooserFactory::SendEvent( | 120 void LayoutTestBluetoothChooserFactory::SendEvent( |
| 121 BluetoothChooser::Event event, | 121 BluetoothChooser::Event event, |
| 122 const std::string& device_id) { | 122 const std::string& device_id) { |
| 123 // Copy |choosers_| to make sure event handler executions that modify | 123 // Copy |choosers_| to make sure event handler executions that modify |
| 124 // |choosers_| don't invalidate iterators. | 124 // |choosers_| don't invalidate iterators. |
| 125 std::vector<Chooser*> choosers_copy(choosers_.begin(), choosers_.end()); | 125 std::vector<Chooser*> choosers_copy(choosers_.begin(), choosers_.end()); |
| 126 for (Chooser* chooser : choosers_copy) { | 126 for (Chooser* chooser : choosers_copy) { |
| 127 chooser->event_handler.Run(event, device_id); | 127 chooser->event_handler.Run(event, device_id); |
| 128 } | 128 } |
| 129 } | 129 } |
| 130 | 130 |
| 131 } // namespace content | 131 } // namespace content |
| OLD | NEW |