| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/shell_integration_linux.h" | 5 #include "chrome/browser/shell_integration_linux.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cstdlib> | 8 #include <cstdlib> |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 " while testing " << test_cases[i].url; | 439 " while testing " << test_cases[i].url; |
| 440 } | 440 } |
| 441 } | 441 } |
| 442 | 442 |
| 443 TEST(ShellIntegrationTest, GetDesktopFileContents) { | 443 TEST(ShellIntegrationTest, GetDesktopFileContents) { |
| 444 const base::FilePath kChromeExePath("/opt/google/chrome/google-chrome"); | 444 const base::FilePath kChromeExePath("/opt/google/chrome/google-chrome"); |
| 445 const struct { | 445 const struct { |
| 446 const char* url; | 446 const char* url; |
| 447 const char* title; | 447 const char* title; |
| 448 const char* icon_name; | 448 const char* icon_name; |
| 449 const char* categories; |
| 449 bool nodisplay; | 450 bool nodisplay; |
| 450 const char* expected_output; | 451 const char* expected_output; |
| 451 } test_cases[] = { | 452 } test_cases[] = { |
| 452 // Real-world case. | 453 // Real-world case. |
| 453 { "http://gmail.com", | 454 { "http://gmail.com", |
| 454 "GMail", | 455 "GMail", |
| 455 "chrome-http__gmail.com", | 456 "chrome-http__gmail.com", |
| 457 "", |
| 456 false, | 458 false, |
| 457 | 459 |
| 458 "#!/usr/bin/env xdg-open\n" | 460 "#!/usr/bin/env xdg-open\n" |
| 459 "[Desktop Entry]\n" | 461 "[Desktop Entry]\n" |
| 460 "Version=1.0\n" | 462 "Version=1.0\n" |
| 461 "Terminal=false\n" | 463 "Terminal=false\n" |
| 462 "Type=Application\n" | 464 "Type=Application\n" |
| 463 "Name=GMail\n" | 465 "Name=GMail\n" |
| 464 "Exec=/opt/google/chrome/google-chrome --app=http://gmail.com/\n" | 466 "Exec=/opt/google/chrome/google-chrome --app=http://gmail.com/\n" |
| 465 "Icon=chrome-http__gmail.com\n" | 467 "Icon=chrome-http__gmail.com\n" |
| 466 "StartupWMClass=gmail.com\n" | 468 "StartupWMClass=gmail.com\n" |
| 467 }, | 469 }, |
| 468 | 470 |
| 469 // Make sure that empty icons are replaced by the chrome icon. | 471 // Make sure that empty icons are replaced by the chrome icon. |
| 470 { "http://gmail.com", | 472 { "http://gmail.com", |
| 471 "GMail", | 473 "GMail", |
| 472 "", | 474 "", |
| 475 "", |
| 473 false, | 476 false, |
| 474 | 477 |
| 475 "#!/usr/bin/env xdg-open\n" | 478 "#!/usr/bin/env xdg-open\n" |
| 476 "[Desktop Entry]\n" | 479 "[Desktop Entry]\n" |
| 477 "Version=1.0\n" | 480 "Version=1.0\n" |
| 478 "Terminal=false\n" | 481 "Terminal=false\n" |
| 479 "Type=Application\n" | 482 "Type=Application\n" |
| 480 "Name=GMail\n" | 483 "Name=GMail\n" |
| 481 "Exec=/opt/google/chrome/google-chrome --app=http://gmail.com/\n" | 484 "Exec=/opt/google/chrome/google-chrome --app=http://gmail.com/\n" |
| 482 #if defined(GOOGLE_CHROME_BUILD) | 485 #if defined(GOOGLE_CHROME_BUILD) |
| 483 "Icon=google-chrome\n" | 486 "Icon=google-chrome\n" |
| 484 #else | 487 #else |
| 485 "Icon=chromium-browser\n" | 488 "Icon=chromium-browser\n" |
| 486 #endif | 489 #endif |
| 487 "StartupWMClass=gmail.com\n" | 490 "StartupWMClass=gmail.com\n" |
| 488 }, | 491 }, |
| 489 | 492 |
| 490 // Test adding NoDisplay=true. | 493 // Test adding categories and NoDisplay=true. |
| 491 { "http://gmail.com", | 494 { "http://gmail.com", |
| 492 "GMail", | 495 "GMail", |
| 493 "chrome-http__gmail.com", | 496 "chrome-http__gmail.com", |
| 497 "Graphics;Education;", |
| 494 true, | 498 true, |
| 495 | 499 |
| 496 "#!/usr/bin/env xdg-open\n" | 500 "#!/usr/bin/env xdg-open\n" |
| 497 "[Desktop Entry]\n" | 501 "[Desktop Entry]\n" |
| 498 "Version=1.0\n" | 502 "Version=1.0\n" |
| 499 "Terminal=false\n" | 503 "Terminal=false\n" |
| 500 "Type=Application\n" | 504 "Type=Application\n" |
| 501 "Name=GMail\n" | 505 "Name=GMail\n" |
| 502 "Exec=/opt/google/chrome/google-chrome --app=http://gmail.com/\n" | 506 "Exec=/opt/google/chrome/google-chrome --app=http://gmail.com/\n" |
| 503 "Icon=chrome-http__gmail.com\n" | 507 "Icon=chrome-http__gmail.com\n" |
| 508 "Categories=Graphics;Education;\n" |
| 504 "NoDisplay=true\n" | 509 "NoDisplay=true\n" |
| 505 "StartupWMClass=gmail.com\n" | 510 "StartupWMClass=gmail.com\n" |
| 506 }, | 511 }, |
| 507 | 512 |
| 508 // Now we're starting to be more evil... | 513 // Now we're starting to be more evil... |
| 509 { "http://evil.com/evil --join-the-b0tnet", | 514 { "http://evil.com/evil --join-the-b0tnet", |
| 510 "Ownz0red\nExec=rm -rf /", | 515 "Ownz0red\nExec=rm -rf /", |
| 511 "chrome-http__evil.com_evil", | 516 "chrome-http__evil.com_evil", |
| 517 "", |
| 512 false, | 518 false, |
| 513 | 519 |
| 514 "#!/usr/bin/env xdg-open\n" | 520 "#!/usr/bin/env xdg-open\n" |
| 515 "[Desktop Entry]\n" | 521 "[Desktop Entry]\n" |
| 516 "Version=1.0\n" | 522 "Version=1.0\n" |
| 517 "Terminal=false\n" | 523 "Terminal=false\n" |
| 518 "Type=Application\n" | 524 "Type=Application\n" |
| 519 "Name=http://evil.com/evil%20--join-the-b0tnet\n" | 525 "Name=http://evil.com/evil%20--join-the-b0tnet\n" |
| 520 "Exec=/opt/google/chrome/google-chrome " | 526 "Exec=/opt/google/chrome/google-chrome " |
| 521 "--app=http://evil.com/evil%20--join-the-b0tnet\n" | 527 "--app=http://evil.com/evil%20--join-the-b0tnet\n" |
| 522 "Icon=chrome-http__evil.com_evil\n" | 528 "Icon=chrome-http__evil.com_evil\n" |
| 523 "StartupWMClass=evil.com__evil%20--join-the-b0tnet\n" | 529 "StartupWMClass=evil.com__evil%20--join-the-b0tnet\n" |
| 524 }, | 530 }, |
| 525 { "http://evil.com/evil; rm -rf /; \"; rm -rf $HOME >ownz0red", | 531 { "http://evil.com/evil; rm -rf /; \"; rm -rf $HOME >ownz0red", |
| 526 "Innocent Title", | 532 "Innocent Title", |
| 527 "chrome-http__evil.com_evil", | 533 "chrome-http__evil.com_evil", |
| 534 "", |
| 528 false, | 535 false, |
| 529 | 536 |
| 530 "#!/usr/bin/env xdg-open\n" | 537 "#!/usr/bin/env xdg-open\n" |
| 531 "[Desktop Entry]\n" | 538 "[Desktop Entry]\n" |
| 532 "Version=1.0\n" | 539 "Version=1.0\n" |
| 533 "Terminal=false\n" | 540 "Terminal=false\n" |
| 534 "Type=Application\n" | 541 "Type=Application\n" |
| 535 "Name=Innocent Title\n" | 542 "Name=Innocent Title\n" |
| 536 "Exec=/opt/google/chrome/google-chrome " | 543 "Exec=/opt/google/chrome/google-chrome " |
| 537 "\"--app=http://evil.com/evil;%20rm%20-rf%20/;%20%22;%20rm%20" | 544 "\"--app=http://evil.com/evil;%20rm%20-rf%20/;%20%22;%20rm%20" |
| 538 // Note: $ is escaped as \$ within an arg to Exec, and then | 545 // Note: $ is escaped as \$ within an arg to Exec, and then |
| 539 // the \ is escaped as \\ as all strings in a Desktop file should | 546 // the \ is escaped as \\ as all strings in a Desktop file should |
| 540 // be; finally, \\ becomes \\\\ when represented in a C++ string! | 547 // be; finally, \\ becomes \\\\ when represented in a C++ string! |
| 541 "-rf%20\\\\$HOME%20%3Eownz0red\"\n" | 548 "-rf%20\\\\$HOME%20%3Eownz0red\"\n" |
| 542 "Icon=chrome-http__evil.com_evil\n" | 549 "Icon=chrome-http__evil.com_evil\n" |
| 543 "StartupWMClass=evil.com__evil;%20rm%20-rf%20_;%20%22;%20" | 550 "StartupWMClass=evil.com__evil;%20rm%20-rf%20_;%20%22;%20" |
| 544 "rm%20-rf%20$HOME%20%3Eownz0red\n" | 551 "rm%20-rf%20$HOME%20%3Eownz0red\n" |
| 545 }, | 552 }, |
| 546 { "http://evil.com/evil | cat `echo ownz0red` >/dev/null", | 553 { "http://evil.com/evil | cat `echo ownz0red` >/dev/null", |
| 547 "Innocent Title", | 554 "Innocent Title", |
| 548 "chrome-http__evil.com_evil", | 555 "chrome-http__evil.com_evil", |
| 556 "", |
| 549 false, | 557 false, |
| 550 | 558 |
| 551 "#!/usr/bin/env xdg-open\n" | 559 "#!/usr/bin/env xdg-open\n" |
| 552 "[Desktop Entry]\n" | 560 "[Desktop Entry]\n" |
| 553 "Version=1.0\n" | 561 "Version=1.0\n" |
| 554 "Terminal=false\n" | 562 "Terminal=false\n" |
| 555 "Type=Application\n" | 563 "Type=Application\n" |
| 556 "Name=Innocent Title\n" | 564 "Name=Innocent Title\n" |
| 557 "Exec=/opt/google/chrome/google-chrome " | 565 "Exec=/opt/google/chrome/google-chrome " |
| 558 "--app=http://evil.com/evil%20%7C%20cat%20%60echo%20ownz0red" | 566 "--app=http://evil.com/evil%20%7C%20cat%20%60echo%20ownz0red" |
| 559 "%60%20%3E/dev/null\n" | 567 "%60%20%3E/dev/null\n" |
| 560 "Icon=chrome-http__evil.com_evil\n" | 568 "Icon=chrome-http__evil.com_evil\n" |
| 561 "StartupWMClass=evil.com__evil%20%7C%20cat%20%60echo%20ownz0red" | 569 "StartupWMClass=evil.com__evil%20%7C%20cat%20%60echo%20ownz0red" |
| 562 "%60%20%3E_dev_null\n" | 570 "%60%20%3E_dev_null\n" |
| 563 }, | 571 }, |
| 564 }; | 572 }; |
| 565 | 573 |
| 566 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) { | 574 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) { |
| 567 SCOPED_TRACE(i); | 575 SCOPED_TRACE(i); |
| 568 EXPECT_EQ( | 576 EXPECT_EQ( |
| 569 test_cases[i].expected_output, | 577 test_cases[i].expected_output, |
| 570 ShellIntegrationLinux::GetDesktopFileContents( | 578 ShellIntegrationLinux::GetDesktopFileContents( |
| 571 kChromeExePath, | 579 kChromeExePath, |
| 572 web_app::GenerateApplicationNameFromURL(GURL(test_cases[i].url)), | 580 web_app::GenerateApplicationNameFromURL(GURL(test_cases[i].url)), |
| 573 GURL(test_cases[i].url), | 581 GURL(test_cases[i].url), |
| 574 std::string(), | 582 std::string(), |
| 575 base::ASCIIToUTF16(test_cases[i].title), | 583 base::ASCIIToUTF16(test_cases[i].title), |
| 576 test_cases[i].icon_name, | 584 test_cases[i].icon_name, |
| 577 base::FilePath(), | 585 base::FilePath(), |
| 586 test_cases[i].categories, |
| 578 test_cases[i].nodisplay)); | 587 test_cases[i].nodisplay)); |
| 579 } | 588 } |
| 580 } | 589 } |
| 581 | 590 |
| 582 TEST(ShellIntegrationTest, GetDesktopFileContentsAppList) { | 591 TEST(ShellIntegrationTest, GetDesktopFileContentsAppList) { |
| 583 const base::FilePath kChromeExePath("/opt/google/chrome/google-chrome"); | 592 const base::FilePath kChromeExePath("/opt/google/chrome/google-chrome"); |
| 584 CommandLine command_line(kChromeExePath); | 593 CommandLine command_line(kChromeExePath); |
| 585 command_line.AppendSwitch("--show-app-list"); | 594 command_line.AppendSwitch("--show-app-list"); |
| 586 EXPECT_EQ( | 595 EXPECT_EQ( |
| 587 "#!/usr/bin/env xdg-open\n" | 596 "#!/usr/bin/env xdg-open\n" |
| 588 "[Desktop Entry]\n" | 597 "[Desktop Entry]\n" |
| 589 "Version=1.0\n" | 598 "Version=1.0\n" |
| 590 "Terminal=false\n" | 599 "Terminal=false\n" |
| 591 "Type=Application\n" | 600 "Type=Application\n" |
| 592 "Name=Chrome App Launcher\n" | 601 "Name=Chrome App Launcher\n" |
| 593 "Exec=/opt/google/chrome/google-chrome --show-app-list\n" | 602 "Exec=/opt/google/chrome/google-chrome --show-app-list\n" |
| 594 "Icon=chrome_app_list\n" | 603 "Icon=chrome_app_list\n" |
| 604 "Categories=Network;WebBrowser;\n" |
| 595 "StartupWMClass=chrome-app-list\n", | 605 "StartupWMClass=chrome-app-list\n", |
| 596 ShellIntegrationLinux::GetDesktopFileContentsForCommand( | 606 ShellIntegrationLinux::GetDesktopFileContentsForCommand( |
| 597 command_line, | 607 command_line, |
| 598 "chrome-app-list", | 608 "chrome-app-list", |
| 599 GURL(), | 609 GURL(), |
| 600 base::ASCIIToUTF16("Chrome App Launcher"), | 610 base::ASCIIToUTF16("Chrome App Launcher"), |
| 601 "chrome_app_list", | 611 "chrome_app_list", |
| 612 "Network;WebBrowser;", |
| 602 false)); | 613 false)); |
| 603 } | 614 } |
| 604 | 615 |
| 605 TEST(ShellIntegrationTest, GetDirectoryFileContents) { | 616 TEST(ShellIntegrationTest, GetDirectoryFileContents) { |
| 606 const struct { | 617 const struct { |
| 607 const char* title; | 618 const char* title; |
| 608 const char* icon_name; | 619 const char* icon_name; |
| 609 const char* expected_output; | 620 const char* expected_output; |
| 610 } test_cases[] = { | 621 } test_cases[] = { |
| 611 // Real-world case. | 622 // Real-world case. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 637 | 648 |
| 638 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) { | 649 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) { |
| 639 SCOPED_TRACE(i); | 650 SCOPED_TRACE(i); |
| 640 EXPECT_EQ( | 651 EXPECT_EQ( |
| 641 test_cases[i].expected_output, | 652 test_cases[i].expected_output, |
| 642 ShellIntegrationLinux::GetDirectoryFileContents( | 653 ShellIntegrationLinux::GetDirectoryFileContents( |
| 643 base::ASCIIToUTF16(test_cases[i].title), | 654 base::ASCIIToUTF16(test_cases[i].title), |
| 644 test_cases[i].icon_name)); | 655 test_cases[i].icon_name)); |
| 645 } | 656 } |
| 646 } | 657 } |
| OLD | NEW |