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

Side by Side Diff: content/browser/dom_storage/local_storage_context_mojo_unittest.cc

Issue 2695333002: Mojo C++ bindings: remove usage of AssociatedGroup from content/ (Closed)
Patch Set: . Created 3 years, 10 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/browser/dom_storage/local_storage_context_mojo.h" 5 #include "content/browser/dom_storage/local_storage_context_mojo.h"
6 6
7 #include "base/files/file_enumerator.h" 7 #include "base/files/file_enumerator.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 struct Observation { 72 struct Observation {
73 enum { kAdd, kChange, kDelete, kDeleteAll } type; 73 enum { kAdd, kChange, kDelete, kDeleteAll } type;
74 std::string key; 74 std::string key;
75 std::string old_value; 75 std::string old_value;
76 std::string new_value; 76 std::string new_value;
77 std::string source; 77 std::string source;
78 }; 78 };
79 79
80 TestLevelDBObserver() : binding_(this) {} 80 TestLevelDBObserver() : binding_(this) {}
81 81
82 mojom::LevelDBObserverAssociatedPtrInfo Bind( 82 mojom::LevelDBObserverAssociatedPtrInfo Bind() {
83 mojo::AssociatedGroup* associated_group) {
84 mojom::LevelDBObserverAssociatedPtrInfo ptr_info; 83 mojom::LevelDBObserverAssociatedPtrInfo ptr_info;
85 binding_.Bind(&ptr_info, associated_group); 84 binding_.Bind(&ptr_info);
86 return ptr_info; 85 return ptr_info;
87 } 86 }
88 87
89 const std::vector<Observation>& observations() { return observations_; } 88 const std::vector<Observation>& observations() { return observations_; }
90 89
91 private: 90 private:
92 void KeyAdded(const std::vector<uint8_t>& key, 91 void KeyAdded(const std::vector<uint8_t>& key,
93 const std::vector<uint8_t>& value, 92 const std::vector<uint8_t>& value,
94 const std::string& source) override { 93 const std::string& source) override {
95 observations_.push_back({Observation::kAdd, Uint8VectorToStdString(key), "", 94 observations_.push_back({Observation::kAdd, Uint8VectorToStdString(key), "",
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 run_loop.QuitClosure(), &result)); 170 run_loop.QuitClosure(), &result));
172 run_loop.Run(); 171 run_loop.Run();
173 return result; 172 return result;
174 } 173 }
175 174
176 private: 175 private:
177 TestBrowserThreadBundle thread_bundle_; 176 TestBrowserThreadBundle thread_bundle_;
178 base::ScopedTempDir temp_path_; 177 base::ScopedTempDir temp_path_;
179 std::map<std::vector<uint8_t>, std::vector<uint8_t>> mock_data_; 178 std::map<std::vector<uint8_t>, std::vector<uint8_t>> mock_data_;
180 MockLevelDBDatabase db_; 179 MockLevelDBDatabase db_;
181 mojo::AssociatedGroup associated_group_;
182 mojo::AssociatedBinding<leveldb::mojom::LevelDBDatabase> db_binding_; 180 mojo::AssociatedBinding<leveldb::mojom::LevelDBDatabase> db_binding_;
183 181
184 scoped_refptr<MockDOMStorageTaskRunner> task_runner_; 182 scoped_refptr<MockDOMStorageTaskRunner> task_runner_;
185 scoped_refptr<DOMStorageContextImpl> dom_storage_context_; 183 scoped_refptr<DOMStorageContextImpl> dom_storage_context_;
186 184
187 std::unique_ptr<LocalStorageContextMojo> context_; 185 std::unique_ptr<LocalStorageContextMojo> context_;
188 186
189 DISALLOW_COPY_AND_ASSIGN(LocalStorageContextMojoTest); 187 DISALLOW_COPY_AND_ASSIGN(LocalStorageContextMojoTest);
190 }; 188 };
191 189
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 context()->OpenLocalStorage(origin2, MakeRequest(&wrapper)); 452 context()->OpenLocalStorage(origin2, MakeRequest(&wrapper));
455 wrapper->Put(key, value, "source", base::Bind(&NoOpSuccess)); 453 wrapper->Put(key, value, "source", base::Bind(&NoOpSuccess));
456 wrapper.reset(); 454 wrapper.reset();
457 455
458 // Make sure all data gets committed to disk. 456 // Make sure all data gets committed to disk.
459 base::RunLoop().RunUntilIdle(); 457 base::RunLoop().RunUntilIdle();
460 EXPECT_FALSE(mock_data().empty()); 458 EXPECT_FALSE(mock_data().empty());
461 459
462 TestLevelDBObserver observer; 460 TestLevelDBObserver observer;
463 context()->OpenLocalStorage(origin1, MakeRequest(&wrapper)); 461 context()->OpenLocalStorage(origin1, MakeRequest(&wrapper));
464 wrapper->AddObserver(observer.Bind(wrapper.associated_group())); 462 wrapper->AddObserver(observer.Bind());
465 base::RunLoop().RunUntilIdle(); 463 base::RunLoop().RunUntilIdle();
466 464
467 context()->DeleteStorage(origin1); 465 context()->DeleteStorage(origin1);
468 base::RunLoop().RunUntilIdle(); 466 base::RunLoop().RunUntilIdle();
469 467
470 ASSERT_EQ(1u, observer.observations().size()); 468 ASSERT_EQ(1u, observer.observations().size());
471 EXPECT_EQ(TestLevelDBObserver::Observation::kDeleteAll, 469 EXPECT_EQ(TestLevelDBObserver::Observation::kDeleteAll,
472 observer.observations()[0].type); 470 observer.observations()[0].type);
473 471
474 // Data from origin2 should exist, including meta-data, but nothing should 472 // Data from origin2 should exist, including meta-data, but nothing should
(...skipping 23 matching lines...) Expand all
498 context()->OpenLocalStorage(origin2, MakeRequest(&wrapper)); 496 context()->OpenLocalStorage(origin2, MakeRequest(&wrapper));
499 wrapper->Put(key, value, "source", base::Bind(&NoOpSuccess)); 497 wrapper->Put(key, value, "source", base::Bind(&NoOpSuccess));
500 wrapper.reset(); 498 wrapper.reset();
501 499
502 // Make sure all data gets committed to disk. 500 // Make sure all data gets committed to disk.
503 base::RunLoop().RunUntilIdle(); 501 base::RunLoop().RunUntilIdle();
504 EXPECT_FALSE(mock_data().empty()); 502 EXPECT_FALSE(mock_data().empty());
505 503
506 TestLevelDBObserver observer; 504 TestLevelDBObserver observer;
507 context()->OpenLocalStorage(origin1, MakeRequest(&wrapper)); 505 context()->OpenLocalStorage(origin1, MakeRequest(&wrapper));
508 wrapper->AddObserver(observer.Bind(wrapper.associated_group())); 506 wrapper->AddObserver(observer.Bind());
509 wrapper->Put(StdStringToUint8Vector("key2"), value, "source", 507 wrapper->Put(StdStringToUint8Vector("key2"), value, "source",
510 base::Bind(&NoOpSuccess)); 508 base::Bind(&NoOpSuccess));
511 base::RunLoop().RunUntilIdle(); 509 base::RunLoop().RunUntilIdle();
512 510
513 context()->DeleteStorage(origin1); 511 context()->DeleteStorage(origin1);
514 base::RunLoop().RunUntilIdle(); 512 base::RunLoop().RunUntilIdle();
515 513
516 ASSERT_EQ(2u, observer.observations().size()); 514 ASSERT_EQ(2u, observer.observations().size());
517 EXPECT_EQ(TestLevelDBObserver::Observation::kAdd, 515 EXPECT_EQ(TestLevelDBObserver::Observation::kAdd,
518 observer.observations()[0].type); 516 observer.observations()[0].type);
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 base::RunLoop().RunUntilIdle(); 842 base::RunLoop().RunUntilIdle();
845 843
846 // Data should have been preserved now. 844 // Data should have been preserved now.
847 context = base::MakeUnique<LocalStorageContextMojo>( 845 context = base::MakeUnique<LocalStorageContextMojo>(
848 connector(), nullptr, base::FilePath(), test_path); 846 connector(), nullptr, base::FilePath(), test_path);
849 EXPECT_TRUE(DoTestGet(context.get(), key, &result)); 847 EXPECT_TRUE(DoTestGet(context.get(), key, &result));
850 EXPECT_EQ(value, result); 848 EXPECT_EQ(value, result);
851 } 849 }
852 850
853 } // namespace content 851 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/dom_storage/local_storage_context_mojo.cc ('k') | content/browser/frame_host/render_frame_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698