SetAndUpdateCacheModel.mm 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright (C) 2012 Apple Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
  14. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  15. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
  17. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  18. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  19. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  20. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  21. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  22. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  23. * THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #include "config.h"
  26. #include <wtf/RetainPtr.h>
  27. #import <WebKit/WebView.h>
  28. #import <WebKit/WebPreferences.h>
  29. @interface WebView (WebViewOtherInternal)
  30. + (WebCacheModel)_cacheModel;
  31. @end
  32. namespace TestWebKitAPI {
  33. TEST(WebKit1, SetAndUpdateCacheModelInitialModel)
  34. {
  35. EXPECT_EQ((int)WebCacheModelDocumentViewer, (int)[WebView _cacheModel]);
  36. RetainPtr<WebView> webView = adoptNS([[WebView alloc] initWithFrame:NSMakeRect(0, 0, 120, 200) frameName:nil groupName:nil]);
  37. EXPECT_EQ((int)WebCacheModelDocumentBrowser, (int)[WebView _cacheModel]);
  38. }
  39. TEST(WebKit1, SetAndUpdateCacheModelStandardPreferenceChange)
  40. {
  41. EXPECT_EQ((int)WebCacheModelDocumentViewer, (int)[WebView _cacheModel]);
  42. WebPreferences *standardPreferences = [WebPreferences standardPreferences];
  43. EXPECT_EQ((int)WebCacheModelDocumentBrowser, (int)[WebView _cacheModel]);
  44. [standardPreferences setCacheModel:WebCacheModelPrimaryWebBrowser];
  45. EXPECT_EQ((int)WebCacheModelPrimaryWebBrowser, (int)[WebView _cacheModel]);
  46. [standardPreferences setCacheModel:WebCacheModelDocumentViewer];
  47. EXPECT_EQ((int)WebCacheModelDocumentViewer, (int)[WebView _cacheModel]);
  48. }
  49. TEST(WebKit1, SetAndUpdateCacheModelPreferencesChangeMix)
  50. {
  51. // On change, the cache model always take the highest value of any preference bound to a WebView.
  52. EXPECT_EQ((int)WebCacheModelDocumentViewer, (int)[WebView _cacheModel]);
  53. WebPreferences *standardPreferences = [WebPreferences standardPreferences];
  54. RetainPtr<WebPreferences> customPreferences = adoptNS([[WebPreferences alloc] initWithIdentifier:@"SetAndUpdateCacheModelPreferencesChangeMix"]);
  55. // 1) The customPreferences is not set on a view.
  56. EXPECT_EQ((int)WebCacheModelDocumentBrowser, (int)[WebView _cacheModel]);
  57. [standardPreferences setCacheModel:WebCacheModelPrimaryWebBrowser];
  58. EXPECT_EQ((int)WebCacheModelPrimaryWebBrowser, (int)[WebView _cacheModel]);
  59. [standardPreferences setCacheModel:WebCacheModelDocumentViewer];
  60. EXPECT_EQ((int)WebCacheModelDocumentViewer, (int)[WebView _cacheModel]);
  61. [customPreferences.get() setCacheModel:WebCacheModelPrimaryWebBrowser];
  62. EXPECT_EQ((int)WebCacheModelPrimaryWebBrowser, (int)[WebView _cacheModel]);
  63. // 2) The cache model should follow the highest value of cache model between the two preferences.
  64. RetainPtr<WebView> webView = adoptNS([[WebView alloc] initWithFrame:NSMakeRect(0, 0, 120, 200) frameName:nil groupName:nil]);
  65. [webView.get() setPreferences:customPreferences.get()];
  66. EXPECT_EQ((int)WebCacheModelPrimaryWebBrowser, (int)[WebView _cacheModel]);
  67. [customPreferences.get() setCacheModel:WebCacheModelDocumentBrowser];
  68. EXPECT_EQ((int)WebCacheModelDocumentBrowser, (int)[WebView _cacheModel]);
  69. [standardPreferences setCacheModel:WebCacheModelPrimaryWebBrowser];
  70. EXPECT_EQ((int)WebCacheModelPrimaryWebBrowser, (int)[WebView _cacheModel]);
  71. [customPreferences.get() setCacheModel:WebCacheModelDocumentViewer];
  72. EXPECT_EQ((int)WebCacheModelPrimaryWebBrowser, (int)[WebView _cacheModel]);
  73. // 3) Resetting the view should fall back to standardPreferences.
  74. [standardPreferences setCacheModel:WebCacheModelDocumentViewer];
  75. [customPreferences.get() setCacheModel:WebCacheModelPrimaryWebBrowser];
  76. EXPECT_EQ((int)WebCacheModelPrimaryWebBrowser, (int)[WebView _cacheModel]);
  77. webView.clear();
  78. EXPECT_EQ((int)WebCacheModelDocumentViewer, (int)[WebView _cacheModel]);
  79. }
  80. } // namespace TestWebKitAPI