summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/webui/chromeos/bluetooth_pairing_ui_browsertest-inl.h
blob: ac37b4181d42a2d38136136aa11510f767d87dc1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/chromeos/bluetooth/bluetooth_pairing_dialog.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/test/base/web_ui_browser_test.h"
#include "content/public/browser/web_ui.h"
#include "content/public/test/browser_test_utils.h"
#include "device/bluetooth/bluetooth_adapter_factory.h"
#include "device/bluetooth/test/mock_bluetooth_adapter.h"
#include "device/bluetooth/test/mock_bluetooth_device.h"
#include "testing/gmock/include/gmock/gmock.h"

class BluetoothPairingUITest : public WebUIBrowserTest {
 public:
  BluetoothPairingUITest();
  ~BluetoothPairingUITest() override;

  void ShowDialog();

 private:
  scoped_refptr<testing::NiceMock<device::MockBluetoothAdapter>> mock_adapter_;
  scoped_ptr<device::MockBluetoothDevice> mock_device_;
};

BluetoothPairingUITest::BluetoothPairingUITest() {}

BluetoothPairingUITest::~BluetoothPairingUITest() {}

void BluetoothPairingUITest::ShowDialog() {
  mock_adapter_ = new testing::NiceMock<device::MockBluetoothAdapter>();
  device::BluetoothAdapterFactory::SetAdapterForTesting(mock_adapter_);
  EXPECT_CALL(*mock_adapter_, IsPresent())
      .WillRepeatedly(testing::Return(true));
  EXPECT_CALL(*mock_adapter_, IsPowered())
      .WillRepeatedly(testing::Return(true));

  const bool kNotPaired = false;
  const bool kNotConnected = false;
  mock_device_.reset(
      new testing::NiceMock<device::MockBluetoothDevice>(
          nullptr,
          0,
          "Bluetooth 2.0 Mouse",
          "28:CF:DA:00:00:00",
          kNotPaired,
          kNotConnected));

  EXPECT_CALL(*mock_adapter_, GetDevice(testing::_))
      .WillOnce(testing::Return(mock_device_.get()));

  chromeos::BluetoothPairingDialog* dialog =
      new chromeos::BluetoothPairingDialog(
          browser()->window()->GetNativeWindow(), mock_device_.get());
  dialog->Show();

  content::WebUI* webui = dialog->GetWebUIForTest();
  content::WebContents* webui_webcontents = webui->GetWebContents();
  content::WaitForLoadStop(webui_webcontents);
  SetWebUIInstance(webui);
}