summaryrefslogtreecommitdiffstats
path: root/content/browser/system_message_window_win_unittest.cc
diff options
context:
space:
mode:
authortpayne@chromium.org <tpayne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-06 00:02:45 +0000
committertpayne@chromium.org <tpayne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-06 00:02:45 +0000
commit85538be95969a67c9969a2448e9a99caa70654d5 (patch)
tree792fc797c0146a16a1a0c49bb8e73c3e38133c5b /content/browser/system_message_window_win_unittest.cc
parentd30237313646c9636991f6cb0d278761dbe775fb (diff)
downloadchromium_src-85538be95969a67c9969a2448e9a99caa70654d5.zip
chromium_src-85538be95969a67c9969a2448e9a99caa70654d5.tar.gz
chromium_src-85538be95969a67c9969a2448e9a99caa70654d5.tar.bz2
Added win media notifier
BUG=110400 TEST=NONE Review URL: http://codereview.chromium.org/9348100 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@125036 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/system_message_window_win_unittest.cc')
-rw-r--r--content/browser/system_message_window_win_unittest.cc172
1 files changed, 172 insertions, 0 deletions
diff --git a/content/browser/system_message_window_win_unittest.cc b/content/browser/system_message_window_win_unittest.cc
new file mode 100644
index 0000000..1db4c19
--- /dev/null
+++ b/content/browser/system_message_window_win_unittest.cc
@@ -0,0 +1,172 @@
+// Copyright (c) 2012 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 "content/browser/system_message_window_win.h"
+
+#include <dbt.h>
+#include <string>
+#include <vector>
+
+#include "base/file_path.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/sys_string_conversions.h"
+#include "base/system_monitor/system_monitor.h"
+#include "base/test/mock_devices_changed_observer.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+LRESULT GetVolumeName(LPCWSTR drive,
+ LPWSTR volume_name,
+ unsigned int volume_name_length) {
+ DCHECK(volume_name_length > wcslen(drive) + 2);
+ *volume_name = 'V';
+ wcscpy(volume_name + 1, drive);
+ return TRUE;
+}
+
+} // namespace
+
+class SystemMessageWindowWinTest : public testing::Test {
+ public:
+ SystemMessageWindowWinTest() : window_(&GetVolumeName) { }
+ virtual ~SystemMessageWindowWinTest() { }
+
+ protected:
+ virtual void SetUp() OVERRIDE {
+ system_monitor_.AddDevicesChangedObserver(&observer_);
+ }
+
+ void DoDevicesAttachedTest(const std::vector<int>& deviceIndices);
+ void DoDevicesDetachedTest(const std::vector<int>& deviceIndices);
+
+ MessageLoop message_loop_;
+ base::SystemMonitor system_monitor_;
+ base::MockDevicesChangedObserver observer_;
+ SystemMessageWindowWin window_;
+};
+
+void SystemMessageWindowWinTest::DoDevicesAttachedTest(
+ const std::vector<int>& device_indices) {
+ DEV_BROADCAST_VOLUME volume_broadcast;
+ volume_broadcast.dbcv_size = sizeof(volume_broadcast);
+ volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME;
+ volume_broadcast.dbcv_unitmask = 0x0;
+ volume_broadcast.dbcv_flags = 0x0;
+ {
+ testing::InSequence sequnce;
+ for (std::vector<int>::const_iterator it = device_indices.begin();
+ it != device_indices.end();
+ ++it) {
+ volume_broadcast.dbcv_unitmask |= 0x1 << *it;
+ std::wstring drive(L"_:\\");
+ drive[0] = 'A' + *it;
+ std::string name("V");
+ name.append(base::SysWideToUTF8(drive));
+ EXPECT_CALL(observer_, OnMediaDeviceAttached(*it, name, FilePath(drive)));
+ }
+ }
+ window_.OnDeviceChange(DBT_DEVICEARRIVAL,
+ reinterpret_cast<DWORD>(&volume_broadcast));
+ message_loop_.RunAllPending();
+};
+
+void SystemMessageWindowWinTest::DoDevicesDetachedTest(
+ const std::vector<int>& device_indices) {
+ DEV_BROADCAST_VOLUME volume_broadcast;
+ volume_broadcast.dbcv_size = sizeof(volume_broadcast);
+ volume_broadcast.dbcv_devicetype = DBT_DEVTYP_VOLUME;
+ volume_broadcast.dbcv_unitmask = 0x0;
+ volume_broadcast.dbcv_flags = 0x0;
+ {
+ testing::InSequence sequence;
+ for (std::vector<int>::const_iterator it = device_indices.begin();
+ it != device_indices.end();
+ ++it) {
+ volume_broadcast.dbcv_unitmask |= 0x1 << *it;
+ EXPECT_CALL(observer_, OnMediaDeviceDetached(*it));
+ }
+ }
+ window_.OnDeviceChange(DBT_DEVICEREMOVECOMPLETE,
+ reinterpret_cast<DWORD>(&volume_broadcast));
+ message_loop_.RunAllPending();
+};
+
+TEST_F(SystemMessageWindowWinTest, DevicesChanged) {
+ EXPECT_CALL(observer_, OnDevicesChanged()).Times(1);
+ window_.OnDeviceChange(DBT_DEVNODES_CHANGED, NULL);
+ message_loop_.RunAllPending();
+}
+
+TEST_F(SystemMessageWindowWinTest, RandomMessage) {
+ window_.OnDeviceChange(DBT_DEVICEQUERYREMOVE, NULL);
+ message_loop_.RunAllPending();
+}
+
+TEST_F(SystemMessageWindowWinTest, DevicesAttached) {
+ std::vector<int> device_indices;
+ device_indices.push_back(1);
+ device_indices.push_back(5);
+ device_indices.push_back(7);
+
+ DoDevicesAttachedTest(device_indices);
+}
+
+TEST_F(SystemMessageWindowWinTest, DevicesAttachedHighBoundary) {
+ std::vector<int> device_indices;
+ device_indices.push_back(25);
+
+ DoDevicesAttachedTest(device_indices);
+}
+
+TEST_F(SystemMessageWindowWinTest, DevicesAttachedLowBoundary) {
+ std::vector<int> device_indices;
+ device_indices.push_back(0);
+
+ DoDevicesAttachedTest(device_indices);
+}
+
+TEST_F(SystemMessageWindowWinTest, DevicesAttachedAdjacentBits) {
+ std::vector<int> device_indices;
+ device_indices.push_back(0);
+ device_indices.push_back(1);
+ device_indices.push_back(2);
+ device_indices.push_back(3);
+
+ DoDevicesAttachedTest(device_indices);
+}
+
+TEST_F(SystemMessageWindowWinTest, DevicesDetached) {
+ std::vector<int> device_indices;
+ device_indices.push_back(1);
+ device_indices.push_back(5);
+ device_indices.push_back(7);
+
+ DoDevicesDetachedTest(device_indices);
+}
+
+TEST_F(SystemMessageWindowWinTest, DevicesDetachedHighBoundary) {
+ std::vector<int> device_indices;
+ device_indices.push_back(25);
+
+ DoDevicesDetachedTest(device_indices);
+}
+
+TEST_F(SystemMessageWindowWinTest, DevicesDetachedLowBoundary) {
+ std::vector<int> device_indices;
+ device_indices.push_back(0);
+
+ DoDevicesDetachedTest(device_indices);
+}
+
+TEST_F(SystemMessageWindowWinTest, DevicesDetachedAdjacentBits) {
+ std::vector<int> device_indices;
+ device_indices.push_back(0);
+ device_indices.push_back(1);
+ device_indices.push_back(2);
+ device_indices.push_back(3);
+
+ DoDevicesDetachedTest(device_indices);
+}