|
9 | 9 | #include <mbgl/style/layers/line_layer.hpp> |
10 | 10 | #include <mbgl/util/io.hpp> |
11 | 11 | #include <mbgl/util/run_loop.hpp> |
| 12 | +#include <mbgl/test/delayed_file_source.hpp> |
12 | 13 |
|
13 | 14 | #include <memory> |
14 | 15 |
|
@@ -110,6 +111,38 @@ TEST(Style, RemoveSourceInUse) { |
110 | 111 | EXPECT_EQ(log.count(logMessage), 1u); |
111 | 112 | } |
112 | 113 |
|
| 114 | +TEST(Style, LoadJSONCancelsPendingLoadURL) { |
| 115 | + util::RunLoop loop; |
| 116 | + |
| 117 | + auto fileSource = std::make_shared<::DelayedFileSource>(); |
| 118 | + Style::Impl style{fileSource, 1.0, {Scheduler::GetBackground(), {}}}; |
| 119 | + |
| 120 | + // Start loading a URL (this will be pending) |
| 121 | + auto url = "http://some-url"; |
| 122 | + style.loadURL(url); |
| 123 | + |
| 124 | + // Before the URL request completes, load JSON directly |
| 125 | + const std::string json = R"STYLE({ |
| 126 | + "version": 8, |
| 127 | + "name": "Test Style", |
| 128 | + "sources": {}, |
| 129 | + "layers": [] |
| 130 | + })STYLE"; |
| 131 | + style.loadJSON(json); |
| 132 | + |
| 133 | + // The style should now be loaded with our JSON content |
| 134 | + ASSERT_EQ("Test Style", style.getName()); |
| 135 | + ASSERT_EQ("", style.getURL()); |
| 136 | + ASSERT_TRUE(style.getJSON().find("Test Style") != std::string::npos); |
| 137 | + |
| 138 | + // Now respond to the original URL request - this should be ignored |
| 139 | + fileSource->respondToRequest(R"STYLE({"version":8,"name":"Streets"})STYLE"); |
| 140 | + |
| 141 | + // The style should still show our JSON content, not the URL content |
| 142 | + ASSERT_EQ("Test Style", style.getName()); |
| 143 | + ASSERT_NE("Streets", style.getName()); |
| 144 | +} |
| 145 | + |
113 | 146 | TEST(Style, SourceImplsOrder) { |
114 | 147 | util::RunLoop loop; |
115 | 148 | auto fileSource = std::make_shared<StubFileSource>(); |
|
0 commit comments