[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / views / extensions / browser_action_drag_data_unittest.cc
blobb808c370c5464b5d4207eaca464db4b5bbb42d50
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/pickle.h"
6 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h"
7 #include "chrome/test/base/testing_profile.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/base/dragdrop/os_exchange_data.h"
10 #include "ui/base/dragdrop/os_exchange_data_provider_win.h"
11 #include "url/gurl.h"
13 namespace {
15 ui::OSExchangeData::Provider* CloneProvider(const ui::OSExchangeData& data) {
16 return new ui::OSExchangeDataProviderWin(
17 ui::OSExchangeDataProviderWin::GetIDataObject(data));
20 } // namespace
22 typedef testing::Test BrowserActionDragDataTest;
24 TEST_F(BrowserActionDragDataTest, ArbitraryFormat) {
25 TestingProfile profile;
26 profile.SetID(L"id");
28 ui::OSExchangeData data;
29 data.SetURL(GURL("http://www.google.com"), L"Title");
31 // We only support our format, so this should not succeed.
32 BrowserActionDragData drag_data;
33 EXPECT_FALSE(drag_data.Read(ui::OSExchangeData(CloneProvider(data))));
36 TEST_F(BrowserActionDragDataTest, BrowserActionDragDataFormat) {
37 TestingProfile profile;
38 Profile* profile_ptr = &profile;
39 profile.SetID(L"id");
41 const std::string extension_id = "42";
42 Pickle pickle;
43 pickle.WriteBytes(&profile_ptr, sizeof(&profile));
44 pickle.WriteString(extension_id);
45 pickle.WriteUInt64(42);
47 ui::OSExchangeData data;
48 data.SetPickledData(BrowserActionDragData::GetBrowserActionCustomFormat(),
49 pickle);
51 BrowserActionDragData drag_data;
52 EXPECT_TRUE(drag_data.Read(ui::OSExchangeData(CloneProvider(data))));
53 ASSERT_TRUE(drag_data.IsFromProfile(profile.GetOriginalProfile()));
54 ASSERT_STREQ(extension_id.c_str(), drag_data.id().c_str());
55 ASSERT_EQ(42, drag_data.index());