Changeset 279444 in webkit
- Timestamp:
- Jun 30, 2021, 4:54:40 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r279439 r279444 1 2021-06-30 Megan Gardner <megan_gardner@apple.com> 2 3 Add ID and versioning support for AppHighlights 4 https://bugs.webkit.org/show_bug.cgi?id=227279 5 6 Reviewed by Tim Horton. 7 8 Allow PersistentDecoders to rewind, to help support v0 highlight data. 9 10 * wtf/persistence/PersistentDecoder.cpp: 11 (WTF::Persistence::Decoder::Decoder): 12 (WTF::Persistence::Decoder::rewind): 13 * wtf/persistence/PersistentDecoder.h: 14 1 15 2021-06-30 Ryosuke Niwa <rniwa@webkit.org> 2 16 -
trunk/Source/WTF/wtf/persistence/PersistentDecoder.cpp
r278253 r279444 67 67 memcpy(data, buffer, size); 68 68 return true; 69 } 70 71 bool Decoder::rewind(size_t size) 72 { 73 if (m_bufferPosition - size >= m_buffer) { 74 m_bufferPosition -= size; 75 return true; 76 } 77 return false; 69 78 } 70 79 -
trunk/Source/WTF/wtf/persistence/PersistentDecoder.h
r278253 r279444 41 41 size_t length() const { return m_bufferEnd - m_buffer; } 42 42 size_t currentOffset() const { return m_bufferPosition - m_buffer; } 43 44 WTF_EXPORT_PRIVATE WARN_UNUSED_RETURN bool rewind(size_t); 43 45 44 46 WTF_EXPORT_PRIVATE WARN_UNUSED_RETURN bool verifyChecksum(); -
trunk/Source/WebCore/ChangeLog
r279443 r279444 1 2021-06-30 Megan Gardner <megan_gardner@apple.com> 2 3 Add ID and versioning support for AppHighlights 4 https://bugs.webkit.org/show_bug.cgi?id=227279 5 6 Reviewed by Tim Horton. 7 8 AppHighlights.AppHighlightRestoreFromStorage 9 AppHighlights.AppHighlightCreateAndRestoreAndDropBytes 10 AppHighlights.AppHighlightCreateAndRestoreWithLaterVersion 11 AppHighlights.AppHighlightCreateAndRestoreWithExtraBytes 12 AppHighlights.AppHighlightRestoreFromStorageV0 13 AppHighlights.AppHighlightRestoreFromStorageV1 14 15 Reformat the storage of Highlight Data to allow for accurate deletion of active 16 highlights, as well as making them more robust and future-proof. Support decoding v0 17 highlights as well. 18 19 * Modules/highlight/AppHighlightRangeData.cpp: 20 (WebCore::AppHighlightRangeData::NodePathComponent::decode): 21 (WebCore::AppHighlightRangeData::encode const): 22 (WebCore::AppHighlightRangeData::decode): 23 * Modules/highlight/AppHighlightRangeData.h: 24 (WebCore::AppHighlightRangeData::NodePathComponent::NodePathComponent): 25 (WebCore::AppHighlightRangeData::AppHighlightRangeData): 26 (WebCore::AppHighlightRangeData::identifier const): 27 (WebCore::AppHighlightRangeData::startOffset const): 28 (WebCore::AppHighlightRangeData::endOffset const): 29 * Modules/highlight/AppHighlightStorage.cpp: 30 (WebCore::createAppHighlightRangeData): 31 1 32 2021-06-30 Ryosuke Niwa <rniwa@webkit.org> 2 33 -
trunk/Source/WebCore/Modules/highlight/AppHighlightRangeData.cpp
r278253 r279444 42 42 namespace WebCore { 43 43 44 constexpr uint64_t highlightFileSignature = 0x4141504832303231; // File Signature (A)pple(AP)plication(H)ighlights(2021) 45 44 46 std::optional<AppHighlightRangeData> AppHighlightRangeData::create(const SharedBuffer& buffer) 45 47 { … … 82 84 return std::nullopt; 83 85 84 std::optional<u nsigned> pathIndex;86 std::optional<uint32_t> pathIndex; 85 87 decoder >> pathIndex; 86 88 if (!pathIndex) … … 92 94 template<class Encoder> void AppHighlightRangeData::encode(Encoder& encoder) const 93 95 { 96 static_assert(!Encoder::isIPCEncoder, "AppHighlightRangeData should not be used by IPC::Encoder"); 97 constexpr uint64_t currentAppHighlightVersion = 1; 98 99 encoder << highlightFileSignature; 100 encoder << currentAppHighlightVersion; 101 encoder << m_identifier; 94 102 encoder << m_text; 95 103 encoder << m_startContainer; … … 101 109 template<class Decoder> std::optional<AppHighlightRangeData> AppHighlightRangeData::decode(Decoder& decoder) 102 110 { 111 static_assert(!Decoder::isIPCDecoder, "AppHighlightRangeData should not be used by IPC::Decoder"); 112 113 std::optional<uint64_t> version; 114 115 std::optional<uint64_t> decodedHighlightFileSignature; 116 decoder >> decodedHighlightFileSignature; 117 if (!decodedHighlightFileSignature) 118 return std::nullopt; 119 if (decodedHighlightFileSignature != highlightFileSignature) { 120 if (!decoder.rewind(sizeof(highlightFileSignature))) 121 return std::nullopt; 122 version = 0; 123 } 124 125 std::optional<String> identifier; 126 if (version) 127 identifier = nullString(); 128 else { 129 decoder >> version; 130 if (!version) 131 return std::nullopt; 132 133 decoder >> identifier; 134 if (!identifier) 135 return std::nullopt; 136 } 137 103 138 std::optional<String> text; 104 139 decoder >> text; … … 111 146 return std::nullopt; 112 147 113 std::optional<u nsigned> startOffset;148 std::optional<uint32_t> startOffset; 114 149 decoder >> startOffset; 115 150 if (!startOffset) … … 121 156 return std::nullopt; 122 157 123 std::optional<u nsigned> endOffset;158 std::optional<uint32_t> endOffset; 124 159 decoder >> endOffset; 125 160 if (!endOffset) 126 161 return std::nullopt; 127 162 128 129 return {{ WTFMove(*text), WTFMove(*startContainer), *startOffset, WTFMove(*endContainer), *endOffset }}; 163 return {{ WTFMove(*identifier), WTFMove(*text), WTFMove(*startContainer), *startOffset, WTFMove(*endContainer), *endOffset }}; 130 164 } 131 165 -
trunk/Source/WebCore/Modules/highlight/AppHighlightRangeData.h
r278340 r279444 44 44 String nodeName; 45 45 String textData; 46 u nsignedpathIndex { 0 };46 uint32_t pathIndex { 0 }; 47 47 48 NodePathComponent(String&& elementIdentifier, String&& name, String&& data, u nsignedindex)48 NodePathComponent(String&& elementIdentifier, String&& name, String&& data, uint32_t index) 49 49 : identifier(WTFMove(elementIdentifier)) 50 50 , nodeName(WTFMove(name)) … … 54 54 } 55 55 56 NodePathComponent(const String& elementIdentifier, const String& name, const String& data, u nsignedindex)56 NodePathComponent(const String& elementIdentifier, const String& name, const String& data, uint32_t index) 57 57 : identifier(elementIdentifier) 58 58 , nodeName(name) … … 80 80 AppHighlightRangeData(const AppHighlightRangeData&) = default; 81 81 AppHighlightRangeData() = default; 82 AppHighlightRangeData(String&& text, NodePath&& startContainer, unsigned startOffset, NodePath&& endContainer, unsigned endOffset) 83 : m_text(WTFMove(text)) 82 AppHighlightRangeData(String&& identifier, String&& text, NodePath&& startContainer, uint64_t startOffset, NodePath&& endContainer, uint64_t endOffset) 83 : m_identifier(WTFMove(identifier)) 84 , m_text(WTFMove(text)) 84 85 , m_startContainer(WTFMove(startContainer)) 85 86 , m_startOffset(startOffset) … … 89 90 } 90 91 91 AppHighlightRangeData(const String& text, const NodePath& startContainer, unsigned startOffset, const NodePath& endContainer, unsigned endOffset) 92 : m_text(text) 92 AppHighlightRangeData(const String& identifier, const String& text, const NodePath& startContainer, uint64_t startOffset, const NodePath& endContainer, uint64_t endOffset) 93 : m_identifier(identifier) 94 , m_text(text) 93 95 , m_startContainer(startContainer) 94 96 , m_startOffset(startOffset) … … 98 100 } 99 101 102 const String& identifier() const { return m_identifier; } 100 103 const String& text() const { return m_text; } 101 104 const NodePath& startContainer() const { return m_startContainer; } 102 u nsignedstartOffset() const { return m_startOffset; }105 uint32_t startOffset() const { return m_startOffset; } 103 106 const NodePath& endContainer() const { return m_endContainer; } 104 u nsignedendOffset() const { return m_endOffset; }107 uint32_t endOffset() const { return m_endOffset; } 105 108 106 109 template<class Encoder> void encode(Encoder&) const; … … 110 113 111 114 private: 115 String m_identifier; 112 116 String m_text; 113 117 NodePath m_startContainer; 114 u nsignedm_startOffset { 0 };118 uint32_t m_startOffset { 0 }; 115 119 NodePath m_endContainer; 116 u nsignedm_endOffset { 0 };120 uint32_t m_endOffset { 0 }; 117 121 }; 118 122 -
trunk/Source/WebCore/Modules/highlight/AppHighlightStorage.cpp
r278253 r279444 44 44 #include "TextIndicator.h" 45 45 #include "TextIterator.h" 46 #include <wtf/UUID.h> 46 47 47 48 namespace WebCore { … … 204 205 auto text = plainText(range); 205 206 text.truncate(textPreviewLength); 207 auto identifier = createCanonicalUUIDString(); 208 206 209 return { 210 identifier, 207 211 text, 208 212 makeNodePath(&range.startContainer()), -
trunk/Source/WebKit/ChangeLog
r279432 r279444 1 2021-06-30 Megan Gardner <megan_gardner@apple.com> 2 3 Add ID and versioning support for AppHighlights 4 https://bugs.webkit.org/show_bug.cgi?id=227279 5 6 Reviewed by Tim Horton. 7 8 Reformat the storage of Highlight Data to allow for accurate deletion of active 9 highlights, as well as making them more robust and future-proof. 10 11 Also found an issue with creating SharedBuffers from the memory map, in that the ipcHandle size 12 should be used instead of the sharedMemory->size(). 13 14 * WebProcess/WebPage/WebPage.cpp: 15 (WebKit::WebPage::restoreAppHighlightsAndScrollToIndex): 16 1 17 2021-06-30 Truitt Savell <tsavell@apple.com> 2 18 -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp
r279420 r279444 7618 7618 continue; 7619 7619 7620 document->appHighlightStorage().restoreAndScrollToAppHighlight(SharedBuffer::create(static_cast<const uint8_t*>(sharedMemory->data()), sharedMemory->size()), i == index ? ScrollToHighlight::Yes : ScrollToHighlight::No);7620 document->appHighlightStorage().restoreAndScrollToAppHighlight(SharedBuffer::create(static_cast<const uint8_t*>(sharedMemory->data()), ipcHandle.dataSize), i == index ? ScrollToHighlight::Yes : ScrollToHighlight::No); 7621 7621 i++; 7622 7622 } -
trunk/Tools/ChangeLog
r279423 r279444 1 2021-06-30 Megan Gardner <megan_gardner@apple.com> 2 3 Add ID and versioning support for AppHighlights 4 https://bugs.webkit.org/show_bug.cgi?id=227279 5 6 Reviewed by Tim Horton. 7 8 * TestWebKitAPI/Tests/WebKitCocoa/WKAppHighlights.mm: 9 (TestWebKitAPI::createAppHighlightWithHTML): 10 (TestWebKitAPI::createWebViewForAppHighlightsWithHTML): 11 (TestWebKitAPI::TEST): 12 1 13 2021-06-30 Wenson Hsieh <wenson_hsieh@apple.com> 2 14 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAppHighlights.mm
r276347 r279444 57 57 namespace TestWebKitAPI { 58 58 59 TEST(AppHighlights, AppHighlightCreateAndRestore)59 RetainPtr<_WKAppHighlight> createAppHighlightWithHTML(NSString *HTMLString, NSString *javaScript, NSString *highlightText) 60 60 { 61 61 WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES]; 62 62 auto delegate = adoptNS([[AppHighlightDelegate alloc] init]); 63 63 auto webViewCreate = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500) configuration:configuration]); 64 auto webViewRestore = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500) configuration:configuration]);65 64 [webViewCreate _setAppHighlightDelegate:delegate.get()]; 66 [webViewCreate synchronouslyLoadHTMLString:@"Test"]; 67 [webViewCreate stringByEvaluatingJavaScript:@"document.execCommand('SelectAll')"]; 68 __block bool finished = NO; 65 [webViewCreate synchronouslyLoadHTMLString:HTMLString]; 66 [webViewCreate stringByEvaluatingJavaScript:javaScript]; 67 __block RetainPtr<_WKAppHighlight> resultHighlight; 68 __block bool done = false; 69 69 [delegate setStoreAppHighlightCallback:^(WKWebView *delegateWebView, _WKAppHighlight *highlight, BOOL inNewGroup, BOOL requestOriginatedInApp) { 70 70 EXPECT_EQ(delegateWebView, webViewCreate.get()); 71 71 EXPECT_NOT_NULL(highlight); 72 EXPECT_WK_STREQ(highlight.text, @"Test");72 EXPECT_WK_STREQ(highlight.text, highlightText); 73 73 EXPECT_NOT_NULL(highlight.highlight); 74 75 [webViewRestore synchronouslyLoadHTMLString:@"Test"]; 76 [webViewRestore _restoreAppHighlights:@[ highlight.highlight ]]; 77 78 TestWebKitAPI::Util::waitForConditionWithLogging([&] () -> bool { 79 return [webViewRestore stringByEvaluatingJavaScript:@"internals.numberOfAppHighlights()"].intValue == 1; 80 }, 2, @"Expected Highlights to be populated."); 81 82 finished = YES; 74 resultHighlight = highlight; 75 done = true; 83 76 }]; 84 77 [webViewCreate _addAppHighlight]; 85 TestWebKitAPI::Util::run(&finished); 78 TestWebKitAPI::Util::run(&done); 79 return resultHighlight; 80 } 81 82 RetainPtr<WKWebView> createWebViewForAppHighlightsWithHTML(NSString *HTMLString) 83 { 84 WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES]; 85 auto webViewRestore = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500) configuration:configuration]); 86 [webViewRestore synchronouslyLoadHTMLString:HTMLString]; 87 88 return webViewRestore; 89 } 90 91 TEST(AppHighlights, AppHighlightCreateAndRestore) 92 { 93 auto highlight = createAppHighlightWithHTML(@"Test", @"document.execCommand('SelectAll')", @"Test"); 94 auto webViewRestore = createWebViewForAppHighlightsWithHTML(@"Test"); 95 96 [webViewRestore _restoreAppHighlights:@[[highlight highlight]]]; 97 98 TestWebKitAPI::Util::waitForConditionWithLogging([&] () -> bool { 99 return [webViewRestore stringByEvaluatingJavaScript:@"internals.numberOfAppHighlights()"].intValue == 1; 100 }, 2, @"Expected Highlights to be populated."); 86 101 } 87 102 88 103 TEST(AppHighlights, AppHighlightCreateAndRestoreAndScroll) 89 104 { 90 WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES]; 91 auto delegate = adoptNS([[AppHighlightDelegate alloc] init]); 92 auto webViewCreate = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500) configuration:configuration]); 105 auto highlight = createAppHighlightWithHTML(@"<div style='height: 10000px'></div>Test", @"document.execCommand('SelectAll')", @"Test"); 106 auto webViewRestore = createWebViewForAppHighlightsWithHTML(@"<div style='height: 10000px'></div>Test"); 107 108 [webViewRestore _restoreAndScrollToAppHighlight:[highlight highlight]]; 109 110 TestWebKitAPI::Util::waitForConditionWithLogging([&] () -> bool { 111 return [webViewRestore stringByEvaluatingJavaScript:@"internals.numberOfAppHighlights()"].intValue == 1; 112 }, 2, @"Expected Highlights to be populated."); 113 EXPECT_NE(0, [[webViewRestore objectByEvaluatingJavaScript:@"pageYOffset"] floatValue]); 114 } 115 116 TEST(AppHighlights, AppHighlightRestoreFailure) 117 { 118 auto highlight = createAppHighlightWithHTML(@"Test", @"document.execCommand('SelectAll')", @"Test"); 119 auto webViewRestore = createWebViewForAppHighlightsWithHTML(@"Not The Same"); 120 121 [webViewRestore _restoreAppHighlights:@[[highlight highlight]]]; 122 123 TestWebKitAPI::Util::waitForConditionWithLogging([&] () -> bool { 124 return ![webViewRestore stringByEvaluatingJavaScript:@"internals.numberOfAppHighlights()"].intValue; 125 }, 2, @"Expected Highlights not to be populated."); 126 } 127 128 // Ensure that future versions of the blob format can add additional data and still be decoded successfully by version of WebKit that only know about the current format. 129 TEST(AppHighlights, AppHighlightCreateAndRestoreWithExtraBytes) 130 { 131 auto highlight = createAppHighlightWithHTML(@"Test", @"document.execCommand('SelectAll')", @"Test"); 132 auto webViewRestore = createWebViewForAppHighlightsWithHTML(@"Test"); 133 134 NSMutableData *modifiedHighlightData = [NSMutableData dataWithData: [highlight highlight] ]; 135 [modifiedHighlightData appendData:[@"TestV2Data" dataUsingEncoding:NSUTF8StringEncoding]]; 136 137 [webViewRestore synchronouslyLoadHTMLString:@"Test"]; 138 [webViewRestore _restoreAppHighlights:@[ modifiedHighlightData ]]; 139 140 TestWebKitAPI::Util::waitForConditionWithLogging([&] () -> bool { 141 return [webViewRestore stringByEvaluatingJavaScript:@"internals.numberOfAppHighlights()"].intValue == 1; 142 }, 2, @"Expected Highlights to be populated."); 143 } 144 145 // Older versions of WebKit need to be able to decode blobs encoded on newer versions of WebKit, so ensure that is possible. 146 TEST(AppHighlights, AppHighlightCreateAndRestoreWithLaterVersion) 147 { 148 auto highlight = createAppHighlightWithHTML(@"Test", @"document.execCommand('SelectAll')", @"Test"); 149 auto webViewRestore = createWebViewForAppHighlightsWithHTML(@"Test"); 150 151 uint64_t maximumVersion = std::numeric_limits<uint64_t>::max(); 152 NSData *versionData = [NSData dataWithBytes:&maximumVersion length:sizeof(maximumVersion)]; 153 NSMutableData *modifiedHighlightData = [NSMutableData dataWithData:[highlight highlight]]; 154 155 [modifiedHighlightData replaceBytesInRange:NSMakeRange(sizeof(uint64_t), sizeof(maximumVersion)) withBytes:versionData]; 156 157 [webViewRestore synchronouslyLoadHTMLString:@"Test"]; 158 [webViewRestore _restoreAppHighlights:@[ modifiedHighlightData ]]; 159 160 TestWebKitAPI::Util::waitForConditionWithLogging([&] () -> bool { 161 return [webViewRestore stringByEvaluatingJavaScript:@"internals.numberOfAppHighlights()"].intValue == 1; 162 }, 2, @"Expected Highlights to be populated."); 163 } 164 165 // Ensure that shorter data blobs will correctly fail to decode. 166 TEST(AppHighlights, AppHighlightCreateAndRestoreAndDropBytes) 167 { 168 auto highlight = createAppHighlightWithHTML(@"Test", @"document.execCommand('SelectAll')", @"Test"); 169 auto webViewRestore = createWebViewForAppHighlightsWithHTML(@"Test"); 170 171 NSMutableData *modifiedHighlightData = [NSMutableData dataWithBytes:[highlight highlight].bytes length:[highlight highlight].length / 2]; 172 173 [webViewRestore synchronouslyLoadHTMLString:@"Test"]; 174 [webViewRestore _restoreAppHighlights:@[ modifiedHighlightData ]]; 175 176 TestWebKitAPI::Util::waitForConditionWithLogging([&] () -> bool { 177 return ![webViewRestore stringByEvaluatingJavaScript:@"internals.numberOfAppHighlights()"].intValue; 178 }, 2, @"Expected Highlights not to be populated."); 179 } 180 181 // Ensure that the original data format will always be able to be decoded in the future. 182 TEST(AppHighlights, AppHighlightRestoreFromStorageV0) 183 { 184 WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES]; 185 const unsigned char bytes[] = {0x04, 0x00, 0x00, 0x00, 0x01, 0x54, 0x65, 0x73, 0x74, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x05, 0x00, 0x00, 0x00, 0x01, 0x23, 0x74, 0x65, 0x78, 0x74, 0x04, 0x00, 0x00, 0x00, 0x01, 0x54, 0x65, 0x73, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x05, 0x00, 0x00, 0x00, 0x01, 0x23, 0x74, 0x65, 0x78, 0x74, 0x04, 0x00, 0x00, 0x00, 0x01, 0x54, 0x65, 0x73, 0x74, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00}; 186 187 NSData *storedData = [NSData dataWithBytes:&bytes length:87]; 188 93 189 auto webViewRestore = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500) configuration:configuration]); 94 [webViewCreate _setAppHighlightDelegate:delegate.get()]; 95 [webViewCreate synchronouslyLoadHTMLString:@"<div style='height: 1000px'></div>Test"]; 96 [webViewCreate stringByEvaluatingJavaScript:@"document.execCommand('SelectAll')"]; 97 __block bool finished = NO; 98 [delegate setStoreAppHighlightCallback:^(WKWebView *delegateWebView, _WKAppHighlight *highlight, BOOL inNewGroup, BOOL requestOriginatedInApp) { 99 EXPECT_EQ(delegateWebView, webViewCreate.get()); 100 EXPECT_NOT_NULL(highlight); 101 EXPECT_WK_STREQ(highlight.text, @"Test"); 102 EXPECT_NOT_NULL(highlight.highlight); 103 104 [webViewRestore synchronouslyLoadHTMLString:@"<div style='height: 1000px'></div>Test"]; 105 [webViewRestore _restoreAndScrollToAppHighlight:highlight.highlight]; 106 107 TestWebKitAPI::Util::waitForConditionWithLogging([&] () -> bool { 108 return [webViewRestore stringByEvaluatingJavaScript:@"internals.numberOfAppHighlights()"].intValue == 1; 109 }, 2, @"Expected Highlights to be populated."); 110 EXPECT_NE(0, [[webViewRestore objectByEvaluatingJavaScript:@"pageYOffset"] floatValue]); 111 112 finished = YES; 113 }]; 114 [webViewCreate _addAppHighlight]; 115 TestWebKitAPI::Util::run(&finished); 116 } 117 118 TEST(AppHighlights, AppHighlightRestoreFailure) 119 { 120 WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES]; 121 auto delegate = adoptNS([[AppHighlightDelegate alloc] init]); 122 auto webViewCreate = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500) configuration:configuration]); 190 191 [webViewRestore synchronouslyLoadHTMLString:@"Test"]; 192 [webViewRestore _restoreAppHighlights:@[ storedData ]]; 193 194 TestWebKitAPI::Util::waitForConditionWithLogging([&] () -> bool { 195 return [webViewRestore stringByEvaluatingJavaScript:@"internals.numberOfAppHighlights()"].intValue == 1; 196 }, 2, @"Expected Highlights to be populated."); 197 } 198 199 200 // Ensure that the V1 data format will always be able to be decoded in the future. 201 TEST(AppHighlights, AppHighlightRestoreFromStorageV1) 202 { 203 WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES]; 204 const unsigned char bytes[] = {0x31, 0x32, 0x30, 0x32, 0x48, 0x50, 0x41, 0x41, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x01, 0x31, 0x36, 0x30, 0x61, 0x36, 0x30, 0x31, 0x62, 0x2d, 0x31, 0x62, 0x37, 0x32, 0x2d, 0x34, 0x31, 0x31, 0x38, 0x2d, 0x62, 0x36, 0x64, 0x31, 0x2d, 0x39, 0x30, 0x32, 0x62, 0x37, 0x34, 0x66, 0x65, 0x61, 0x36, 0x36, 0x31, 0x04, 0x00, 0x00, 0x00, 0x01, 0x54, 0x65, 0x73, 0x74, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x05, 0x00, 0x00, 0x00, 0x01, 0x23, 0x74, 0x65, 0x78, 0x74, 0x04, 0x00, 0x00, 0x00, 0x01, 0x54, 0x65, 0x73, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x05, 0x00, 0x00, 0x00, 0x01, 0x23, 0x74, 0x65, 0x78, 0x74, 0x04, 0x00, 0x00, 0x00, 0x01, 0x54, 0x65, 0x73, 0x74, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00}; 205 206 NSData *storedData = [NSData dataWithBytes:&bytes length:144]; 207 123 208 auto webViewRestore = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500) configuration:configuration]); 124 [webViewCreate _setAppHighlightDelegate:delegate.get()]; 125 [webViewCreate synchronouslyLoadHTMLString:@"Test"]; 126 [webViewCreate stringByEvaluatingJavaScript:@"document.execCommand('SelectAll')"]; 127 __block bool finished = NO; 128 [delegate setStoreAppHighlightCallback:^(WKWebView *delegateWebView, _WKAppHighlight *highlight, BOOL inNewGroup, BOOL requestOriginatedInApp) { 129 EXPECT_EQ(delegateWebView, webViewCreate.get()); 130 EXPECT_NOT_NULL(highlight); 131 EXPECT_WK_STREQ(highlight.text, @"Test"); 132 EXPECT_NOT_NULL(highlight.highlight); 133 134 [webViewRestore synchronouslyLoadHTMLString:@"Not the same"]; 135 [webViewRestore _restoreAppHighlights:@[ highlight.highlight ]]; 136 137 TestWebKitAPI::Util::waitForConditionWithLogging([&] () -> bool { 138 return ![webViewRestore stringByEvaluatingJavaScript:@"internals.numberOfAppHighlights()"].intValue; 139 }, 2, @"Expected Highlights to be populated."); 140 141 finished = YES; 142 }]; 143 [webViewCreate _addAppHighlight]; 144 TestWebKitAPI::Util::run(&finished); 209 210 [webViewRestore synchronouslyLoadHTMLString:@"Test"]; 211 [webViewRestore _restoreAppHighlights:@[ storedData ]]; 212 213 TestWebKitAPI::Util::waitForConditionWithLogging([&] () -> bool { 214 return [webViewRestore stringByEvaluatingJavaScript:@"internals.numberOfAppHighlights()"].intValue == 1; 215 }, 2, @"Expected Highlights to be populated."); 145 216 } 146 217
Note:
See TracChangeset
for help on using the changeset viewer.