OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "webkit/support/test_webkit_platform_support.h" | 5 #include "webkit/support/test_webkit_platform_support.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/metrics/stats_counters.h" | 9 #include "base/metrics/stats_counters.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 WebKit::WebString TestWebKitPlatformSupport::defaultLocale() { | 335 WebKit::WebString TestWebKitPlatformSupport::defaultLocale() { |
336 return ASCIIToUTF16("en-US"); | 336 return ASCIIToUTF16("en-US"); |
337 } | 337 } |
338 | 338 |
339 WebKit::WebStorageNamespace* | 339 WebKit::WebStorageNamespace* |
340 TestWebKitPlatformSupport::createLocalStorageNamespace( | 340 TestWebKitPlatformSupport::createLocalStorageNamespace( |
341 const WebKit::WebString& path, unsigned quota) { | 341 const WebKit::WebString& path, unsigned quota) { |
342 return dom_storage_system_.CreateLocalStorageNamespace(); | 342 return dom_storage_system_.CreateLocalStorageNamespace(); |
343 } | 343 } |
344 | 344 |
345 // Wrap a WebKit::WebIDBFactory to rewrite the data directory to | |
346 // a scoped temp directory. In multiprocess Chromium this is rewritten | |
347 // to a real profile directory during IPC. | |
348 class TestWebIDBFactory : public WebKit::WebIDBFactory { | |
349 public: | |
350 TestWebIDBFactory() { | |
351 // Create a new temp directory for Indexed DB storage, specific to this | |
352 // factory. If this fails, WebKit uses in-memory storage. | |
353 if (!indexed_db_dir_.CreateUniqueTempDir()) { | |
354 LOG(WARNING) << "Failed to create a temp dir for Indexed DB, " | |
355 "using in-memory storage."; | |
356 DCHECK(indexed_db_dir_.path().empty()); | |
357 } | |
358 data_dir_ = webkit_support::GetAbsoluteWebStringFromUTF8Path( | |
359 indexed_db_dir_.path().AsUTF8Unsafe()); | |
360 | |
361 // Lazily construct factory_ so that it gets allocated on the thread where | |
362 // it will be used. TestWebIDBFactory gets allocated on the main thread. | |
363 } | |
364 | |
365 virtual void getDatabaseNames(WebKit::WebIDBCallbacks* callbacks, | |
366 const WebKit::WebSecurityOrigin& origin, | |
367 WebKit::WebFrame* frame, | |
368 const WebString& dataDir) { | |
369 EnsureFactory(); | |
370 factory_->getDatabaseNames(callbacks, origin, frame, | |
371 dataDir.isEmpty() ? data_dir_ : dataDir); | |
372 } | |
373 | |
374 virtual void open(const WebString& name, | |
375 long long version, | |
376 long long transaction_id, | |
377 WebKit::WebIDBCallbacks* callbacks, | |
378 WebKit::WebIDBDatabaseCallbacks* databaseCallbacks, | |
379 const WebKit::WebSecurityOrigin& origin, | |
380 WebKit::WebFrame* frame, | |
381 const WebString& dataDir) { | |
382 EnsureFactory(); | |
383 factory_->open(name, version, transaction_id, callbacks, | |
384 databaseCallbacks, origin, frame, | |
385 dataDir.isEmpty() ? data_dir_ : dataDir); | |
386 } | |
387 | |
388 virtual void deleteDatabase(const WebString& name, | |
389 WebKit::WebIDBCallbacks* callbacks, | |
390 const WebKit::WebSecurityOrigin& origin, | |
391 WebKit::WebFrame* frame, | |
392 const WebString& dataDir) { | |
393 EnsureFactory(); | |
394 factory_->deleteDatabase(name, callbacks, origin, frame, | |
395 dataDir.isEmpty() ? data_dir_ : dataDir); | |
396 } | |
397 private: | |
398 void EnsureFactory() { | |
399 if (!factory_) | |
400 factory_.reset(WebKit::WebIDBFactory::create()); | |
401 } | |
402 | |
403 scoped_ptr<WebIDBFactory> factory_; | |
404 base::ScopedTempDir indexed_db_dir_; | |
405 WebString data_dir_; | |
406 }; | |
407 | |
408 WebKit::WebIDBFactory* TestWebKitPlatformSupport::idbFactory() { | |
409 return new TestWebIDBFactory(); | |
410 } | |
411 | |
412 #if defined(OS_WIN) || defined(OS_MACOSX) | 345 #if defined(OS_WIN) || defined(OS_MACOSX) |
413 void TestWebKitPlatformSupport::SetThemeEngine(WebKit::WebThemeEngine* engine) { | 346 void TestWebKitPlatformSupport::SetThemeEngine(WebKit::WebThemeEngine* engine) { |
414 active_theme_engine_ = engine ? | 347 active_theme_engine_ = engine ? |
415 engine : WebKitPlatformSupportImpl::themeEngine(); | 348 engine : WebKitPlatformSupportImpl::themeEngine(); |
416 } | 349 } |
417 | 350 |
418 WebKit::WebThemeEngine* TestWebKitPlatformSupport::themeEngine() { | 351 WebKit::WebThemeEngine* TestWebKitPlatformSupport::themeEngine() { |
419 return active_theme_engine_; | 352 return active_theme_engine_; |
420 } | 353 } |
421 #endif | 354 #endif |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 // TODO(jamesr): Support TestViewTypeLayoutTest. | 589 // TODO(jamesr): Support TestViewTypeLayoutTest. |
657 DCHECK_EQ(TestViewTypeUnitTest, type); | 590 DCHECK_EQ(TestViewTypeUnitTest, type); |
658 scoped_ptr<WebKit::WebLayerTreeViewImplForTesting> view( | 591 scoped_ptr<WebKit::WebLayerTreeViewImplForTesting> view( |
659 new WebKit::WebLayerTreeViewImplForTesting); | 592 new WebKit::WebLayerTreeViewImplForTesting); |
660 if (!view->initialize()) | 593 if (!view->initialize()) |
661 return NULL; | 594 return NULL; |
662 return view.release(); | 595 return view.release(); |
663 } | 596 } |
664 #endif | 597 #endif |
665 | 598 |
OLD | NEW |