Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Side by Side Diff: third_party/WebKit/Source/core/clipboard/DataObjectTest.cpp

Issue 2875013002: DataTransfer: Make |types| be a FrozenArray<DOMString>. (Closed)
Patch Set: Fix win_chromium_compile_dbg_ng Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "core/clipboard/DataObject.h" 5 #include "core/clipboard/DataObject.h"
6 6
7 #include "core/clipboard/DataObjectItem.h" 7 #include "core/clipboard/DataObjectItem.h"
8 #include "platform/testing/UnitTestHelpers.h" 8 #include "platform/testing/UnitTestHelpers.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
11 namespace blink { 11 namespace blink {
12 12
13 class DataObjectTest : public ::testing::Test { 13 class DataObjectTest : public ::testing::Test {
14 public: 14 public:
15 DataObjectTest() : data_object_(DataObject::Create()) {} 15 DataObjectTest() : data_object_(DataObject::Create()) {}
16 16
17 protected: 17 protected:
18 Persistent<DataObject> data_object_; 18 Persistent<DataObject> data_object_;
19 }; 19 };
20 20
21 class DataObjectObserver : public GarbageCollected<DataObjectObserver>,
22 public DataObject::Observer {
23 USING_GARBAGE_COLLECTED_MIXIN(DataObjectObserver);
24
25 public:
26 DataObjectObserver() : call_count_(0) {}
27 void OnItemListChanged() override { call_count_++; }
28 size_t call_count() { return call_count_; }
29
30 private:
31 size_t call_count_;
32 };
33
34 TEST_F(DataObjectTest, DataObjectObserver) {
35 DataObjectObserver* observer = new DataObjectObserver;
36 data_object_->AddObserver(observer);
37
38 data_object_->ClearAll();
39 EXPECT_EQ(0U, data_object_->length());
40 EXPECT_EQ(0U, observer->call_count());
41
42 data_object_->SetData("text/plain", "foobar");
43 EXPECT_EQ(1U, data_object_->length());
44 EXPECT_EQ(1U, observer->call_count());
45
46 DataObjectItem* item = data_object_->Add("bar quux", "text/plain");
47 EXPECT_EQ(nullptr, item);
48 EXPECT_EQ(1U, data_object_->length());
49 EXPECT_EQ(1U, observer->call_count());
50
51 item = data_object_->Add("bar quux", "application/octet-stream");
52 EXPECT_NE(nullptr, item);
53 EXPECT_EQ(2U, data_object_->length());
54 EXPECT_EQ(2U, observer->call_count());
55
56 data_object_->DeleteItem(42);
57 EXPECT_EQ(2U, data_object_->length());
58 EXPECT_EQ(2U, observer->call_count());
59
60 data_object_->DeleteItem(0);
61 EXPECT_EQ(1U, data_object_->length());
62 EXPECT_EQ(3U, observer->call_count());
63
64 DataObjectObserver* observer2 = new DataObjectObserver;
65 data_object_->AddObserver(observer2);
66
67 String file_path = testing::BlinkRootDir();
68 file_path.append("/Source/core/clipboard/DataObjectTest.cpp");
69 data_object_->AddFilename(file_path, String(), String());
70 EXPECT_EQ(2U, data_object_->length());
71 EXPECT_EQ(4U, observer->call_count());
72 EXPECT_EQ(1U, observer2->call_count());
73
74 data_object_->ClearData("application/octet-stream");
75 EXPECT_EQ(1U, data_object_->length());
76 EXPECT_EQ(5U, observer->call_count());
77 EXPECT_EQ(2U, observer2->call_count());
78
79 data_object_->ClearAll();
80 EXPECT_EQ(0U, data_object_->length());
81 EXPECT_EQ(6U, observer->call_count());
82 EXPECT_EQ(3U, observer2->call_count());
83 }
84
21 TEST_F(DataObjectTest, addItemWithFilenameAndNoTitle) { 85 TEST_F(DataObjectTest, addItemWithFilenameAndNoTitle) {
22 String file_path = testing::BlinkRootDir(); 86 String file_path = testing::BlinkRootDir();
23 file_path.append("/Source/core/clipboard/DataObjectTest.cpp"); 87 file_path.append("/Source/core/clipboard/DataObjectTest.cpp");
24 88
25 data_object_->AddFilename(file_path, String(), String()); 89 data_object_->AddFilename(file_path, String(), String());
26 EXPECT_EQ(1U, data_object_->length()); 90 EXPECT_EQ(1U, data_object_->length());
27 91
28 DataObjectItem* item = data_object_->Item(0); 92 DataObjectItem* item = data_object_->Item(0);
29 EXPECT_EQ(DataObjectItem::kFileKind, item->Kind()); 93 EXPECT_EQ(DataObjectItem::kFileKind, item->Kind());
30 94
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 } 144 }
81 145
82 { 146 {
83 DataObjectItem* item = data_object_->Item(2); 147 DataObjectItem* item = data_object_->Item(2);
84 EXPECT_TRUE(item->HasFileSystemId()); 148 EXPECT_TRUE(item->HasFileSystemId());
85 EXPECT_EQ("fileSystemIdForFileSystemFile", item->FileSystemId()); 149 EXPECT_EQ("fileSystemIdForFileSystemFile", item->FileSystemId());
86 } 150 }
87 } 151 }
88 152
89 } // namespace blink 153 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/clipboard/DataObject.cpp ('k') | third_party/WebKit/Source/core/clipboard/DataTransfer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698